-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support throwing MismatchedInputException
when deserializing properties that are not part of the view
#437
Comments
Ok. I think I understand the request. Will need to see how easy this would be to implement. |
Maybe the semantics of the DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES optin is large enough to cover the case already? Would need feedback from actual deserialization view users, which I'm not yet. |
Yes, semantics could cover, but behavioral changes are always risky. |
I just ran into this myself. For what it is worth, I believe this would be the place to do the test and throw com.fasterxml.jackson.databind.deser.BeanDeserializer#deserializeWithView:
So, rather than simply skipping children and continuing, test the configuration and throw if appropriate. |
@davideanderson thank you; this should help in figuring out how to make it work; sounds like there'd be all access needed to see what should be the action. |
Hmmh. Just realized something: number of |
I think the place that @davideanderson pointed out is appropriate and @cowtowncoder I get your point, that this could break working code, but since I see this as a bug, I think it's okay to make this change without introducing a new DeserializationFeature like FAIL_ON_DISABLED_BY_VIEW. Otherwise the call to handleUnknownProperty would need to be toggled by this feature. |
@simontb Yes, I am sure you would be perfectly happy by my changing of feature to make it work like you want, and then my getting to support literally dozens of bug reports by very annoyed users with production system that start failing when do patch-level update. :-D Seriously tho I take backwards compatibility seriously, based on my experiences as the maintainer and think that such a change would be a Wrong Thing To Do in 2.9.x patch. And risky even in minor version (2.9 -> 2.10, if such was released). I do actually agree that behavior can be surprising; and that expected behavior is not specified one way or another -- consider the fact that properties ARE known to deserializer, they just are not to be included in the view. |
I totally agree, that an incompatible change shouldn't be a patch.
Very good point. I didn't see it from that perspective. Maybe |
@simontb I appreciate your feedback and ideas. I often find my view that seems intuitive and self-evident to me is nothing of kind to many others. It is difficult to consider things from other perspectives after seeing them make sense from one. So... I think I need to think about how to handle this: I think expectation of being able to sort of prohibit properties that are excluded by active View is perfectly reasonable one, among alternative expectations. And as such it should be possible to change. A new |
Any updates on this? |
Just another data point from my side. CONTEXT: I am building a new REST service so legacy considerations do not affect me (not currently, I am very aware how important legacy is). I am currently using a view to restrict what fields can be updated via HTTP PATCH requests with JSON payloads, i.e. the allowed fields are annotated CONCLUSION 1: CONCLUSION 2: RECOMMENDATION: Hope this helps. |
UnrecognizedPropertyException
when deserializing properties that are not part of the view
UnrecognizedPropertyException
when deserializing properties that are not part of the viewMismatchedInputException
when deserializing properties that are not part of the view
Implemented via #4275 with new |
Using a deserialization view and DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, it could be convenient if an error was raised when attempting to deserialize a property that is not part of the view.
In the following example code, the property annotatedWithView2 (which is not part of the deserialization view, View1) is correctly ignored during deserialization, but no error is raised.
This could be seen as an extension of #343 for views.
The text was updated successfully, but these errors were encountered: