Filter out problem+json mime type from JSON mime types (#9680)

This commit is contained in:
Payal Gadura
2021-06-10 12:59:22 -04:00
committed by GitHub
parent bd18ba6b41
commit 98ae4ab614
2 changed files with 20 additions and 2 deletions

View File

@@ -497,6 +497,15 @@ public class ApiClient extends JavaTimeFormatter {
return mediaType != null && (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType) || mediaType.getSubtype().matches("^.*\\+json[;]?\\s*$"));
}
/**
* Check if the given {@code String} is a Problem JSON MIME (RFC-7807).
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents Problem JSON, false otherwise
*/
public boolean isProblemJsonMime(String mediaType) {
return "application/problem+json".equalsIgnoreCase(mediaType);
}
/**
* Select the Accept header's value from the given accepts array:
* if JSON exists in the given array, use it;
@@ -511,7 +520,7 @@ public class ApiClient extends JavaTimeFormatter {
}
for (String accept : accepts) {
MediaType mediaType = MediaType.parseMediaType(accept);
if (isJsonMime(mediaType)) {
if (isJsonMime(mediaType) && !isProblemJsonMime(accept)) {
return Collections.singletonList(mediaType);
}
}