-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix errant “accept anything” handling of providers #162
base: master
Are you sure you want to change the base?
Conversation
When `hasMatchingMediaType` returns `true` by default, it is impossible to have a catch-all provider, or even a sensible and predicatable error, when the response doesn’t have a content-type.
It would great to consider this as a "bug" and consider backporting these changes. Working with multiple formats and detecting an unsupported or errant format is impossible the way it currently is. |
Ok. I don't think this can be backported due to very likely compatibility issues: some users are likely to rely on default behavior. Timing-wise, either way I just released the last RC for 2.14 so this will have to wait until 2.15, unless there was a way to make it so that:
It might make sense to bring this up on "jackson-dev" google group since while description makes sense, I think I'd like others to voice their opinions. Especially considering that this setting has been there for past 8+ years or so... meaning I don't think it can be exactly obvious flaw. |
Wether or not it can be back ported or may be relied upon for current users is a debate to be had for sure, but I have to disagree with it not being an obvious flaw. The entire point of This becomes a big issue when supporting multiple formats. For example we support JSON and CBOR. As it stands if no media type is present, whatever format is queried first is assumed to be the format and you generally get a nondescript error. We added our own catch all (i.e. |
I am not arguing so much about it not being problematic. But from purely pragmatic viewpoint I am surprised no one else considered this problematic enough to report a bug. And I would be guessing that this is considered a "feature, not bug" by some developers who want defaulting and do not support multiple media types. Once again I am not arguing this is proper way to think about things (it is sloppy) but that change here would cause breakage for anyone relying on current behavior. |
@cowtowncoder Given that #194 was merged and to some extent tightens up this behavior. Is it time to get this fix in to? |
FYI... we use the variant feature quite a bit to switch between JSON/YAML/CBOR and in my experience it is the JAX-RS implementation that should be selecting a "default". This generally allows more nuanced decision making; additionally, major frameworks seem to already handle this. For example, Quarkus & Spring select JSON (by default or configuration) if no MB(Reader|Writer) returns In general, adding this modules just breaks all of that specialized handling because Jackson has effectively committed to handling "everything" in all of its providers. |
Another point of information your decision is, this isn't easy to fix, even when you known there's a problem. We handle this now but deriving our own YAMLProvider and CBORProvider like so (please excuse the Kotlin): @Provider
@Produces(WILDCARD) // Allow handling of suffixed types (e.g. `+cbor`, `+yaml`
@Consumes(WILDCARD) // Wildcard is not an issue when isReadable/isWritable return proper values
@Priority(Priorities.USER)
class YAMLProvider : JacksonYAMLProvider {
override hasMatchingMediaType(MediaType mediaType) {
// Check for application/yaml and `+yaml` and then let Quarkus/JAX-RS decide.
return false
}
} Unfortunately this doesn't work, after a bit of testing you will conclude you need two things
All in all, this can be quite a nuisance and hard to keep correctly working. Quarkus has had major changes to their Reactive JAX-RS that are tripped up by this and our code must adapt accordingly; thankfully proper testing ensures we are able to detect these problems. |
@kdubb Apologies for super-slow follow-up, but I am back and I agree with your assessment: change is desirable. So as to how/where to make the change, I think this should go in the next 2.x minor release, 2.19. So target branch should be 2.19 (easier to merge forward). So: would it be possible to create a new PR targeting 2.19, adding new If so, would be happy to get this merged & I can handle rolling forward to master/3.0. |
When
hasMatchingMediaType
returnstrue
by default, it is impossible to have a catch-all provider, or even a sensible and predicatable error, when the response doesn’t have a content-type.