-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Jackson 2.6: message converter should use type only for collections [SPR-13318] #17903
Comments
Rossen Stoyanchev commented From a brief look it might be just a matter of passing |
Oliver Drotbohm commented This ticket in Spring Boot seems to be running into the same issue. The newly introduced clause in I think the change is suboptimal as it might bring benefit in a very narrow case: en empty collection or map being returned as favoring the return type will allow to reason about the element type in that case which was impossible if only the value type was inspected. However, this completely breaks the rendering for value types being returned for more abstract declared return types, as Jackson will use that reference to look up the serializer to be used and thus not render any properties that only the actual value carries or even fail to find a serializer in the first place (as shown above). Maybe we should restrict this special behavior the case of collections being returned as I think this is what the ticket the fix was introduced for was originally requesting. I've created a test case that reproduces the error described in the Boot ticket by showing the additional properties of a Spring HATEOAS |
Sébastien Deleuze commented Indeed, I think the best we can do here is to add an additional check and use types only for collection, as detected by Jackson 2.6+ here. This fix proposal makes Oliver test case green, and is likely to fix this issue reported by Markus. Are you ok with these changes Oliver Drotbohm and Rossen Stoyanchev? |
Oliver Drotbohm commented Thanks for taking the time so quickly, Sébastien. The fix generally looks good to me. I still think passing in
|
Sébastien Deleuze commented Indeed. I think I found what causes the confusion around this I have also updated the original commit in order to contain only the additional |
Sébastien Deleuze commented These changes are now in master and will be available in our next Oliver Drotbohm Markus Heiden Could you please validate that these changes fix your issue(s)? |
Oliver Drotbohm commented I can confirm the explicitly introduced integration tests now producing correct serialization results in Spring HATEOAS. |
Sébastien Deleuze commented Thanks for your feedback Olie. |
Markus Heiden opened SPR-13318 and commented
All our JSON entities implement an interface which is not annotated with Jackson annotations. Since using Jackson 2.6.0 the code snippet below of AbstractJackson2HttpMessageConverter#writeInternal(Object, Type, HttpOutputMessage) causes javaType always to be detected as the not annotated interface instead of the concrete JSON entity class. And Jackson later on complains about not finding any serializer for it.
Affects: 4.2 GA
Issue Links:
@ResponseBody
method return type available to message converters1 votes, 10 watchers
The text was updated successfully, but these errors were encountered: