Description
After going through a couple issues, I came to understand that Jackson always uses declared type of value to figure out whether to include type information. This is done to ensure that type settings are identical between serialization and deserialization.
However isn't that statement false for templated class?. This robustness would be better ensured if the type id settings would be bound to declared types for all untemplated classes but were bound to both declaration and component classes for templated classes. This would imply obtaining the type information at runtime, thus serialisation/deserialisation of templated classes would be a little bit less efficient but that drawback would be negligeable at least in my case.
This would allow for serialisation/deserialisation of Templated classes who's component class are abstract ex. List
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(name = "ItemADto", value = ItemADto.class)
@JsonSubTypes.Type(name = "ItemBDto", value = ItemBDto.class)
})
public abstract class AbstractItemDto {...}
@JsonTypeName("ItemADto")
public class ItemADto {...}
@JsonTypeName("ItemBDto")
public class ItemBDto {...}