I have a list of abstract class
List<Messaging> data;
Messages are an abstract class, and 3 more classes extend this class.
For instance,
Message class extends Messaging
Product class extends Messaging
Filter class extends Messaging
I add all the messages in the list above
I used @JsonTypeInfo for the message class, as shown below:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
@JsonSubTypes({
@Type(value = Message.class, name = "message"),
@Type(value = Filter.class, name = "filter"),
@Type(value = Product.class , name = "product")})
When I serialize this Java object to JSON using jackson, I get the values as shown below:
{
"@type": "message",
"type": "text",
"value": "Is this the information you need"
}
I need my value as below:
"message" : {
"type": "text",
"value": "Is this the information you need"
}
How to serialize a list of polymorphic object to different node?
source
share