Jackson Glossary: SimpleAbstractTypeResolver
Package: org.codehaus.jackson.map.module
Jar: jackson-mapper
Role
This is a basic static implementation of AbstractTypeResolver, which uses explicit mappings from abstract classes to sub-classes that implement them. A typical usage is to define exact implementation classes to use: for example, to ensure that anything declared as java.util.List will be of type java.util.LinkedList you would add a mapping from List to LinkedList.
Usage
Although instance of this type can be registered via DeserializationConfig, most common way is to use SimpleModule to register abstract type fallbacks like so:
1 ObjectMapper mapper = new ObjectMapper();
2 SimpleModule module = new SimpleModule("test", Version.unknownVersion());
3 module.addAbstractTypeMapping(List.class, LinkedList.class);
4 mapper.registerModule(module); // important, otherwise won't have any effect on mapper's configuration
5 List<?> list = mapper.readValue("[]", List.class);
6 // this is now true: without settings, type would be ArrayList
7 assertEquals(LinkedList.class, list.getClass());
Super type
Extends AbstractTypeResolver
Notes
Note that type defaulting will only be applied to abstract types (interfaces, abstract classes), not concrete classes.
Back to Jackson Term Glossary
