I am limited to this JSON structure:
{
  "metadata": {
    "eventName": "FooEvent",
    "field1": "bla"
  },
  "event": { ... }
}
How can I deserialize it using polymorphic deserialization and a property of information of a nested type? I use a metadata.eventNamenested property in the @JsonTypeInfofollowing way:
@JsonTypeInfo(
    use = Id.NAME,
    include = As.EXISTING_PROPERTY,
    visible = true,
    property = "metadata.eventName"
)
@JsonSubTypes({
    @Type(name="fooEvent", value = FooEvent.class)
    @Type(name="barEvent", value = BarEvent.class)
})
public class EventPayload<T> {
     private Metadata metadata;
     private T event;
}
Given that the Jackson configuration complains that the property could not be found:
com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'metadata.eventName' that is to contain type id  (for class EventPayload)
 at [Source: {
  "metadata": {
     "eventName": "FooEvent",
     "field1": "bla"
  },
  "content": { ... }
}; line: 16, column: 1]
source
share