jackson-jaxrs-providers
jackson-jaxrs-providers copied to clipboard
Media type matching is potentially too restrictive
Suppose an HTTP client submits a request to the server with header "Accept: /" or even no accept header at all. Clearly, a json response is acceptable here. In both cases jersey will set the MediaType of the request to "/" (in the absense of any @Produces annotation on the resource method).
The code eventually comes to jackson-jaxrs-json-provider-2.9.6-sources.jar:com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider:hasMatchingMediaType which returns false for MediaType.WILDCARD_TYPE.
I think that in this case it should return true. And by extension it should return true for application/* media types.
In other words, mediaType = MediaType.WILDCARD_TYPE should be handled in the same way as mediaType = null.
https://github.com/FasterXML/jackson-jaxrs-providers/blob/9958c0347e90f6f6509fca36f4731da006c2a86b/json/src/main/java/com/fasterxml/jackson/jaxrs/json/JacksonJsonProvider.java#L168
Should be easy to add in 2.11 (too risky for inclusion in patches, like 2.10.3). But would be great would be a test case to show expected usage -- do clients actually send wildcard matches? Or, rather, does Jersey (et al) map empty/missing Accept
header as wild card?
Also: should the same change be made for all format providers, not just json? I assume so?
My main concern here is actually that behavioral change may break some users, so there is also question of downsides, potential breakages.
Would need a reproduction and/or PR here; will leave open for now but may close in near future.