public class AbstractJackson2Codec
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.util.List<MimeType> |
JSON_MIME_TYPES |
static java.lang.String |
JSON_VIEW_HINT
Hint key to use with a
Class value specifying the JSON View to use to serialize
or deserialize an object. |
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(java.lang.reflect.Type type,
java.lang.Class<?> contextClass)
Return the Jackson
JavaType for the specified type and context class. |
private ResolvableType |
resolveVariable(java.lang.reflect.TypeVariable<?> typeVariable,
ResolvableType contextType) |
public static final java.lang.String JSON_VIEW_HINT
Class
value specifying the JSON View to use to serialize
or deserialize an object.protected static final java.util.List<MimeType> JSON_MIME_TYPES
protected final ObjectMapper mapper
protected AbstractJackson2Codec(ObjectMapper mapper)
mapper
- the Jackson ObjectMapper to useprotected JavaType getJavaType(java.lang.reflect.Type type, java.lang.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
)private ResolvableType resolveVariable(java.lang.reflect.TypeVariable<?> typeVariable, ResolvableType contextType)