On Tue, May 15, 2018 at 6:01 AM, Suat Gönül <[email protected]> wrote: > Hi folks, > > I have two auto-generated classes as follows: > > > public class DataMonitoringClauseType extends ClauseType { > } > > public class ClauseType { > } > > As the classes are autogenerated I cannot define additional annotations like > JsonSubType for them. > > I have a third object with a list of ClauseTypes as follows: > > > public class RootClass { > List<ClauseType> clauses; > } > > > Given a serialized RootClass, is there a way to deserialize the RootClass > instance such that I would have DataMonitoringClauseType instances inside > the clauses list?
There are a few ways to make that happen: 1. Use mix-in annotations to add "@JsonDeserialize(as=ImplementationType.class)" into abstract type 2. Create `SimpleModule` configured with "addAbstractTypeMapping(....)", which establishes the implementation type to use (note: can only add implementations to abstract types, not concrete classes, as per name) 3. On `List` valued property, add annotation (regular or mixin) to indicate type of values @JsonDeserialize(contentAs = DataMonitoringClauseType.class) List<ClauseType> >clauses; Hope this helps, -+ Tatu +- -- 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.
