json - Unexpected duplicate key error using @JsonTypeInfo property -


i have simple hierarchy of data objects, have converted json format. this:

@jsontypeinfo(use = jsontypeinfo.id.name, include = jsontypeinfo.as.property, property = "documenttype") @jsonsubtypes({@type(transcriptiondocument.class), @type(archivedocument.class)}) public class document{   private string documenttype;   //other fields, getters/setters }  @jsontypename("archive") public class archivedocument extends document { ... }  @jsontypename("transcriptions") public class transcriptiondocument extends document { ... } 

upon json parsing encounter errors one: unexpected duplicate key:documenttype @ position 339. , because in generated json there 2 documenttype fields.

what should changed make jsontypename value appear in documenttype field, without error (eg replacing other value)?

jackson version 2.2

your code doesn't show it, bet have getter in document class documenttype property. should annotate getter @jsonignore so:

@jsonignore public string getdocumenttype() {     return documenttype; } 

there implicit documenttype property associated each subclass, having same property in parent class causes serialized twice.

another option remove getter altogether, assume might need business logic, @jsonignore annotation might best option.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -