Skip to content

Problem with type specialization for Maps with @JsonDeserialize(as=subtype) #1215

@brentryan

Description

@brentryan

If I have json that looks like

{
  "something": [
        {
           "id": "a uuid",
           "property": "value"
         }
  ]
}

And I have a java pojo with an annotation like this:

    @JsonDeserialize(as = MyHashMap.class)
    private void setSomething(Map<UUID, Foo> incomingValue) {

Where MyHashMap.java has some custom logic using generics that allow us to map the array json above into a Map where "id" is the key and everything else serializes into the value. We use generics on MyHashMap to enforce that every value implements a certain interface that respects the contract of returning an "id" property. In this example Foo.java implements this interface MyCustomIdInterface.java.

When using 2.6.6 this worked fine, but if I switch to 2.7.x then it breaks with the error:

Can not construct instance of MyCustomIdInterface, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information

in 2.7.x, it looks like jackson resolves to using AbstractDeserializer based on MyCustomIdInterface but in 2.6.6 it resolves to using BeanDeserializer based on Foo.java.

Is this a bug or is there some default/feature flag that changed here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions