public class MappingJackson2MessageConverter extends AbstractMessageConverter
MessageConverter
implementation.
Compatible with Jackson 2.1 and higher.
logger
Constructor and Description |
---|
MappingJackson2MessageConverter() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canConvertFrom(Message<?> message,
Class<?> targetClass) |
protected boolean |
canConvertTo(Object payload,
MessageHeaders headers) |
Object |
convertFromInternal(Message<?> message,
Class<?> targetClass)
Convert the message payload from serialized form to an Object.
|
Object |
convertToInternal(Object payload,
MessageHeaders headers)
Convert the payload object to serialized form.
|
protected JsonEncoding |
getJsonEncoding(MimeType contentType)
Determine the JSON encoding to use for the given content type.
|
ObjectMapper |
getObjectMapper()
Return the underlying
ObjectMapper for this converter. |
void |
setObjectMapper(ObjectMapper objectMapper)
Set the
ObjectMapper for this converter. |
void |
setPrettyPrint(boolean prettyPrint)
Whether to use the
DefaultPrettyPrinter when writing JSON. |
protected boolean |
supports(Class<?> clazz)
Whether the given class is supported by this converter.
|
fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage
public void setObjectMapper(ObjectMapper objectMapper)
ObjectMapper
for this converter.
If not set, a default ObjectMapper
is used.
Setting a custom-configured ObjectMapper
is one way to take further
control of the JSON serialization process. For example, an extended
SerializerFactory
can be
configured that provides custom serializers for specific types. The other
option for refining the serialization process is to use Jackson's provided
annotations on the types to be serialized, in which case a custom-configured
ObjectMapper is unnecessary.
public ObjectMapper getObjectMapper()
ObjectMapper
for this converter.public void setPrettyPrint(boolean prettyPrint)
DefaultPrettyPrinter
when writing JSON.
This is a shortcut for setting up an ObjectMapper
as follows:
ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); converter.setObjectMapper(mapper);
protected boolean canConvertFrom(Message<?> message, Class<?> targetClass)
canConvertFrom
in class AbstractMessageConverter
protected boolean canConvertTo(Object payload, MessageHeaders headers)
canConvertTo
in class AbstractMessageConverter
protected boolean supports(Class<?> clazz)
AbstractMessageConverter
supports
in class AbstractMessageConverter
clazz
- the class to test for supporttrue
if supported; false
otherwisepublic Object convertFromInternal(Message<?> message, Class<?> targetClass)
AbstractMessageConverter
convertFromInternal
in class AbstractMessageConverter
public Object convertToInternal(Object payload, MessageHeaders headers)
AbstractMessageConverter
convertToInternal
in class AbstractMessageConverter
protected JsonEncoding getJsonEncoding(MimeType contentType)
contentType
- the MIME type from the MessageHeaders, if anynull
)