I use Jackson to convert a large Json string to various classes and subclasses.
I have a list of objects, each of which contains a node object, the last result object and a child array. The array of children contains a list of objects with the same setting. This continues for 3 or 4 layers.
Each node layer has a different subclass that extends to the superclass of the node class. I annotated the superclass node with the following annotations:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = Type1ResponseDto.class, name = "Type1"), @JsonSubTypes.Type(value = Type2ResponseDto.class, name = "Type2"), @JsonSubTypes.Type(value = Type3ResponseDto.class, name = "Type3"), @JsonSubTypes.Type(value = Type4ResponseDto.class, name = "Type4"), @JsonSubTypes.Type(value = Type5ResponseDto.class, name = "Type5") })
This seems to work as all subclasses are displayed.
However, this somehow leads to the fact that the type property is null.
Any ideas as to why this is happening?
source share