public class AbstractJackson2Codec extends Object
Modifier and Type | Field and Description |
---|---|
protected static List<MimeType> |
JSON_MIME_TYPES |
static String |
JSON_VIEW_HINT |
protected ObjectMapper |
mapper |
Modifier | Constructor and Description |
---|---|
protected |
AbstractJackson2Codec(ObjectMapper mapper)
Create a new Jackson codec for the given mapper.
|
Modifier and Type | Method and Description |
---|---|
protected JavaType |
getJavaType(Type type,
Class<?> contextClass)
Return the Jackson
JavaType for the specified type and context class. |
public static final String JSON_VIEW_HINT
protected final ObjectMapper mapper
protected AbstractJackson2Codec(ObjectMapper mapper)
mapper
- the Jackson ObjectMapper to useprotected JavaType getJavaType(Type type, Class<?> contextClass)
JavaType
for the specified type and context class.
The default implementation returns typeFactory.constructType(type, contextClass)
,
but this can be overridden in subclasses, to allow for custom generic collection handling.
For instance:
protected JavaType getJavaType(Type type) { if (type instanceof Class && List.class.isAssignableFrom((Class)type)) { return TypeFactory.collectionType(ArrayList.class, MyBean.class); } else { return super.getJavaType(type); } }
type
- the generic type to return the Jackson JavaType forcontextClass
- a context class for the target type, for example a class
in which the target type appears in a method signature (can be null
)