I have a simple hierarchy of data objects, which have to be converted to JSON format. Like 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 I encounter errors like this one:
Unexpected duplicate key:documentType at position 339.
, because in the generated JSON there are actually two documentType
fields.
What should be changed to make JsonTypeName
value appear in documentType
field, without an error (eg replacing the other value)?
Jackson version is 2.2