I know that 3 years have passed since the initial question, but the properties of the nested points are still not supported, and perhaps this will help someone. I ended up creating the NestedTypeResolver class, so we can use the dot syntax as expected. Just add @JsonTypeResolver(NestedTypeResolver.class) to any class with nested discriminators, and the original poster attempt will work:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type.id") @JsonSubTypes({ @JsonSubTypes.Type(value = MealDisplayModel.class, name = "MEAL"), @JsonSubTypes.Type(value = EntertainmentDisplayModel.class, name = "ENTERTAINMENT") }) @JsonTypeResolver(NestedTypeResolver.class) public abstract class ActivityDisplayModel {
NestedTypeResolver:
public class NestedTypeResolver extends StdTypeResolverBuilder { @Override public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes) {
All the hard work is done here, NestedTypeDeserializer:
public class NestedTypeDeserializer extends AsPropertyTypeDeserializer { private static final Logger LOGGER = LoggerFactory.getLogger(NestedTypeDeserializer.class); public NestedTypeDeserializer(JavaType bt, TypeIdResolver idRes, String typePropertyName, boolean typeIdVisible, JavaType defaultImpl) { super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl); } public NestedTypeDeserializer(JavaType bt, TypeIdResolver idRes, String typePropertyName, boolean typeIdVisible, JavaType defaultImpl, JsonTypeInfo.As inclusion) { super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl, inclusion); } public NestedTypeDeserializer(AsPropertyTypeDeserializer src, BeanProperty property) { super(src, property); } @Override public TypeDeserializer forProperty(BeanProperty prop) { return (prop == _property) ? this : new NestedTypeDeserializer(this, prop); } @Override public Object deserializeTypedFromObject(JsonParser p, DeserializationContext ctxt) throws IOException { JsonNode originalNode = p.readValueAsTree(); JsonNode node = originalNode;
Disclaimer: we used this for a month with Jackson 2.8.10 and did not have any problems, but we needed to delve into the weeds of the Jackson source code to execute it, therefore YMMV. Hopefully Jackson will ever resolve this because of the box, so we donβt need these workarounds.