-
-
Notifications
You must be signed in to change notification settings - Fork 143
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 is ignored when serializing collections #281
Comments
@PavelPenkov Not really; Collections and arrays both include type information, but Java Type Erasure only affects former: Lists/Collections (etc) are generic, whereas arrays are not generic. Problem specifically is that when you pass There are various work-arounds;
in which case type information is passed explicitly and incomplete runtime type information ignored. Hope this helps! |
@cowtowncoder I thought JsonTypeInfo could be found by walking up the type heirarchy of the object being serialized even when type information was not available. Why does it matter what "known" types (i.e. using type references or non-gen subtypes) there are on the collection? |
@nbauernfeind No, type info handling must be based on statically available information to guarantee (well, try to anyway) deserialization can use same base definition. For performance reasons it would also be prohibitive to dig into these details on element-by-element basis; but fundamentally collections are considered to be homogenous with respect to "base type", which is what polymorphic type handling uses. So, for example, for property like: public class Foo { only Actual content serialization is dynamic, however, so all properties of elements are serialized; and type id itself of course relies on actual type during serialization. From this, then, root value handling differs in that instead of finding This question is a FAQ and I really should try to formulate it in an easily referenceable form; it is something that will not be changed at this point, and has been the behavior since polymorphic handling was implemented (in Jackson 1.5 I think). |
It seems that
@JsonTypeInfo
annotation is only used when serializing arrays of objects and ignored for other types of collections. Tested on 2.8.2The text was updated successfully, but these errors were encountered: