Is this a bug - DeserializationConfig.introspect seems unaware of abstract type mapping

4 views
Skip to first unread message

Bojan Tomic

unread,
May 26, 2019, 1:45:55 PM5/26/19
to jackson-user
Here's a code sample illustrating what I find to be a surprising behavior:

//Just some interface
public interface Named {
    String getName();
}

//The implementation
public class Concrete implements Named {

    @Override
    public String getName() {
        ...
    }

    public void setName(String name) {
        ...
    }
}

//Make Jackson aware that Named can be deserialized as Concrete
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule mod = new SimpleModule("XXXXXX");
mod.addAbstractTypeMapping(Named.class, Concrete.class);
objectMapper = objectMapper.registerModule(mod);

//Inspect the detected deserializable properties on Named
JavaType javaType = objectMapper.getTypeFactory().constructType(Named.class);
BeanDescription desc = objectMapper.getDeserializationConfig().introspect(javaType);

//Check to see if name is deserializable
desc.findProperties().get(0).couldDeserialize(); //It isn't?


Is it normal that DeserializationConfig says it won't be able to deserialize the name property, despite having a concrete type registered?


Reply all
Reply to author
Forward
0 new messages