I am not sure I understand the question wrt requiring no-arguments constructor: yes, any object that Jackson is to create must be constructed somehow: and choice is usually either via zero-arguments constructor, or a constructor with `@JsonCreator` annotation.
What exactly is the exception you get? And what does the class being deserialized look like wrt consructors it has? -+ Tatu +- On Fri, May 12, 2017 at 4:28 PM, Rob Sargent <[email protected]> wrote: > I'm generating classes with these annotations > @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, > property="class") > @JsonTypeName("persist.seg.tables.pojos.Segment") > and I generate json such as > > { > "userName" : "rob", > "segmentList" : [ { > "class" : "persist.seg.tables.pojos.Segment", > "id" : "d4fca0dc-c20f-436d-b2d5-45950c148357", > "chrom" : 1, > "markersetId" : "668ea0fd-e028-408f-bc46-58691aaf194e", > "probandsetId" : "48f7be44-87b7-4aec-8a8f-6eff0ff21da2", > "startbase" : 1123456, > "endbase" : 1223456, > "eventsGreater" : 299000, > "eventsEqual" : 300, > "eventsLess" : 700 > }, { > "class" : "persist.seg.tables.pojos.Segment", > "id" : "52a8116d-8f68-4950-8641-730b4d99b34c", > "chrom" : 1, > "markersetId" : "668ea0fd-e028-408f-bc46-58691aaf194e", > "probandsetId" : "48f7be44-87b7-4aec-8a8f-6eff0ff21da2", > "startbase" : 1123456, > "endbase" : 1223456, > "eventsGreater" : 299900, > "eventsEqual" : 30, > "eventsLess" : 70 > }, { > "class" : "persist.seg.tables.pojos.Segment", > "id" : "c021517a-5b3e-48b8-928c-7790c0fe9a73", > "chrom" : 1, > "markersetId" : "668ea0fd-e028-408f-bc46-58691aaf194e", > "probandsetId" : "48f7be44-87b7-4aec-8a8f-6eff0ff21da2", > "startbase" : 1123456, > "endbase" : 1223456, > "eventsGreater" : 299990, > "eventsEqual" : 3, > "eventsLess" : 7 > } ] > } > > But without a no-argument constructor the deserialization fails. I thought > the annotations would answer the suggestion in the error message "perhaps > need to add/enable type information?" > > On Thursday, October 6, 2016 at 9:57:18 PM UTC-6, krrrr38 wrote: >> >> Hi. I use jackson-databind 2.8.3. >> >> I want to serialize value with `@JsonTypeName`. When serialize with >> `List`, the property value is not shown. >> >> public class Main { >> public static void main(String[] args) throws Exception { >> ObjectMapper om = new ObjectMapper(); >> System.out.println(om.writeValueAsString(new ExampleContent())); >> System.out.println(om.writeValueAsString(Arrays.asList(new >> ExampleContent()))); >> } >> >> @JsonTypeInfo( >> use = JsonTypeInfo.Id.NAME, >> include = JsonTypeInfo.As.PROPERTY, >> property = "type", >> visible = true >> ) >> @JsonSubTypes({ >> @JsonSubTypes.Type(ExampleContent.class) >> }) >> abstract static public class AbstractContent { >> } >> >> @JsonTypeName("text") >> public static class ExampleContent extends AbstractContent { >> } >> } >> >> >> result >> >> {"type":"text"} >> [{}] >> >> >> expected? >> >> {"type":"text"} >> [{"type":"text"}] >> >> Do I need to add more annotation or something? >> >> Regargs. >> > -- > 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. -- 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.
