-
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
Make @ResponseBody method return type available to message converters [SPR-12811] #17408
Comments
Juergen Hoeller commented Sébastien Deleuze, I suppose we could change the
Would that have any negative side effects? Should it rather be conditional? Juergen |
Juergen Hoeller commented Hmm, this seems to be what Jackson is doing without a Juergen |
Miroslav Senaj commented This is strange because If I manually convert my List of objects using ObjectMapper like:
It generates correct output with "type" in it. |
Sébastien Deleuze commented I am not sure this is an issue on Spring side. When using When using a wrapper like Maybe we could create an issue on jackson-databind bugtracker, asking to improve Jackson Please also notice that Jackson bugtracker contains a lot of issues related to TypeInfo. Any thoughts ? |
Juergen Hoeller commented A framework cannot use the I suppose we could introspect the In any case, this is a rather involved improvement then, so I'm turning this into a 4.2-only issue along those lines. Juergen |
Rossen Stoyanchev commented
Note that we support this on the reading side, see GenericHttpMessageConverter, since otherwise Jackson would have no way of knowing how to read the body to something like List<Foo>. We didn't do the same for the writing side where the starting point is an actual object and the assumption is it should be possible to obtain all necessary information. Perhaps we can extend GenericHttpMessageConverter to include the writing side. Otherwise Jackson would have to do something to look at the List elements. |
Sébastien Deleuze commented This commit adds
See also #17745 for the same improvement applied to request body serialization. |
Sébastien Deleuze commented This commit enables serialization with type only with Jackson 2.6+ since previous versions do not serialize polymorphic collections correctly when the type is specified. See FasterXML/jackson-databind#727 for the related Jackson fix. |
Miroslav Senaj opened SPR-12811 and commented
In Spring MVC I have following object hierarchy.
ACTUAL:
When I generate response from method as List<ParentClass> it generates JSON without "type" : "foo" or "type" : "bar".
EXPECTED:
In List<T> response type it should generate "type" as well.
TRIVIA:
When I return from
@Controller
in@ResponseBody
object which contains List<ParentClass> asIt generates proper response with proper "type" in it.
See also stackoverflow issue
What I found so far that in
org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter:228
this.objectMapper.writerWithView(serializationView).writeValue(generator, value);
Is serializing data without its type and base on this topic it should have writerWithType in order to write type.
Affects: 4.1.1
Issue Links:
Referenced from: commits 31a5434, 3bff7bd
1 votes, 6 watchers
The text was updated successfully, but these errors were encountered: