Hello!
I'm working on client libraries for a service, and one of the apis can
return a heterogeneous list of items sorted alphabetically. There are two
possible types in this list. A sample response might be:
<Items>
<TypeA>
<Name1>
</TypeA>
<TypeB>
<Name2>
</TypeB>
<TypeA>
<Name3>
</TypeA>
<TypeA>
<Name4>
</TypeA>
<TypeB>
<Name5>
</TypeB>
<TypeB>
<Name6>
</TypeB>
<TypeA>
<Name7>
</TypeA>
<TypeB>
<Name8>
</TypeB>
<TypeB>
<Name9>
</TypeB>
</Items>
TypeA and TypeB are returned as one list and ordered by name, but each has
a different set of properties. The goal is to deserialize this into two
separate lists based on their types, the result list being (the object's
name here representing the entire object):
listOfTypeA={Name1,Name3,Name4, Name7} and listOfTypeB={Name2,
Name5,Name6,Name8,Name9}. Instead what we get is listOfTypeA={Name7} and
listOfTypeB={Name8, Name9}.
I have stepped through the code and confirmed that the reason for this
behavior is that each time an item of TypeA is encountered, a new list is
created, and the list property on the parent object is overwritten, with
the end result that only the last contiguous set of each of the types is
persisted and returned. More specifically, the CollectionDeserializer
instantiates a new list with each call to deserialize.
Our object structure is a parent type called Items corresponding to the
root xml element, which has ArrayList<TypeA> and ArrayList<TypeB>. The
fields are annotated with @JsonProperty() and their respective type name.
This is using Jackson databind 2.8.11.
Is there any way to configure Jackson to deserialize this list with the
desired behavior? or should I create a feature request/issue?
Thank you for your help.
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.