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
JsonTypeInfo ignored when serializing a plain list #1816
Comments
Ok, this needs to go in FAQ. It gets asked on monthly basis. :) Yes, this is as expected: the only type that Jackson can see (due to Java Type Erasure) is There are couple of work-arounds here:
both of which work. But in general it may be best to simply avoid use of generic types as root value if possible. |
Uh, apologies -- I did scan the bug database, but didn't find it somehow. I understand why it doesn't work, but still think it's confusing as hell: my assumption was that if the polymorphic tags were specified on the contents of a list, they would be retrieved from each element upon serialization. I see how this can be a challenge on deserialization though (if the typing information isn't globally unique, such as a class name). |
@dweiss There are many reports, but since this is not really a bug but feature it's difficult to find issues. I really need to spend time documenting this as FAQ. As to handling: per-element determination is not made due to a few different reasons
Of these (2) is bigger. Effectively all elements of a container type (Collection, array, Map) must have same base type, configuration of which is used for all elements. |
Yup, clear. Thank you and sorry for the noise. |
@dweiss No problem at all. I can see how this is surprising and sub-optimal. I just would like to make it easier to figure this out since it is quite intricate. And I may be one of few people who know it fully, having implemented the system... took a while and is partly complicated due to configurability of various aspect. |
JsonTypeInfo seems to be ignored entirely if the serialized value is a list (and not embedded in another bean). This is present with the most recent 2.8.9.
Repro:
Produces this:
I'd expect the second line to have the 'type' property information as well?
The text was updated successfully, but these errors were encountered: