Class JacksonJsonMessageConverter
java.lang.Object
org.springframework.messaging.converter.AbstractMessageConverter
org.springframework.messaging.converter.JacksonJsonMessageConverter
- All Implemented Interfaces:
MessageConverter, SmartMessageConverter
A Jackson 3.x based
MessageConverter
implementation.- Since:
- 7.0
- Author:
- Sebastien Deleuze
-
Field Summary
Fields inherited from class AbstractMessageConverter
logger
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
.JacksonJsonMessageConverter
(MimeType... supportedMimeTypes) Construct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
and the providedMimeType
s.JacksonJsonMessageConverter
(tools.jackson.databind.json.JsonMapper mapper) Construct a new instance with the providedJsonMapper
.JacksonJsonMessageConverter
(tools.jackson.databind.json.JsonMapper.Builder builder) Construct a new instance with the providedJsonMapper.Builder
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
.JacksonJsonMessageConverter
(tools.jackson.databind.json.JsonMapper.Builder builder, MimeType... supportedMimeTypes) Construct a new instance with the providedJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
, and the providedMimeType
s.JacksonJsonMessageConverter
(tools.jackson.databind.json.JsonMapper mapper, MimeType... supportedMimeTypes) Construct a new instance with the providedJsonMapper
and the providedMimeType
s. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
canConvertFrom
(Message<?> message, @Nullable Class<?> targetClass) protected boolean
canConvertTo
(Object payload, @Nullable MessageHeaders headers) convertFromInternal
(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) Convert the message payload from serialized form to an Object.convertToInternal
(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) Convert the payload object to serialized form.protected tools.jackson.core.JsonEncoding
getJsonEncoding
(@Nullable MimeType contentType) Determine the JSON encoding to use for the given content type.protected tools.jackson.databind.json.JsonMapper
Return the underlyingJsonMapper
for this converter.getSerializationView
(@Nullable Object conversionHint) Determine a Jackson serialization view based on the given conversion hint.protected boolean
Whether the given class is supported by this converter.Methods inherited from class AbstractMessageConverter
addSupportedMimeTypes, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessage
-
Constructor Details
-
JacksonJsonMessageConverter
public JacksonJsonMessageConverter()Construct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
. -
JacksonJsonMessageConverter
-
JacksonJsonMessageConverter
public JacksonJsonMessageConverter(tools.jackson.databind.json.JsonMapper mapper) Construct a new instance with the providedJsonMapper
.- See Also:
-
JacksonJsonMessageConverter
public JacksonJsonMessageConverter(tools.jackson.databind.json.JsonMapper.Builder builder) Construct a new instance with the providedJsonMapper.Builder
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
.- See Also:
-
JacksonJsonMessageConverter
-
JacksonJsonMessageConverter
-
-
Method Details
-
getJsonMapper
protected tools.jackson.databind.json.JsonMapper getJsonMapper()Return the underlyingJsonMapper
for this converter. -
canConvertFrom
- Overrides:
canConvertFrom
in classAbstractMessageConverter
-
canConvertTo
- Overrides:
canConvertTo
in classAbstractMessageConverter
-
supports
Description copied from class:AbstractMessageConverter
Whether the given class is supported by this converter.- Specified by:
supports
in classAbstractMessageConverter
- Parameters:
clazz
- the class to test for support- Returns:
true
if supported;false
otherwise
-
convertFromInternal
protected @Nullable Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) Description copied from class:AbstractMessageConverter
Convert the message payload from serialized form to an Object.- Overrides:
convertFromInternal
in classAbstractMessageConverter
- Parameters:
message
- the input messagetargetClass
- the target class for the conversionconversionHint
- an extra object passed to theMessageConverter
, for example, the associatedMethodParameter
(may benull
)- Returns:
- the result of the conversion, or
null
if the converter cannot perform the conversion
-
convertToInternal
protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) Description copied from class:AbstractMessageConverter
Convert the payload object to serialized form.- Overrides:
convertToInternal
in classAbstractMessageConverter
- Parameters:
payload
- the Object to convertheaders
- optional headers for the message (may benull
)conversionHint
- an extra object passed to theMessageConverter
, for example, the associatedMethodParameter
(may benull
)- Returns:
- the resulting payload for the message, or
null
if the converter cannot perform the conversion
-
getSerializationView
Determine a Jackson serialization view based on the given conversion hint.- Parameters:
conversionHint
- the conversion hint Object as passed into the converter for the current conversion attempt- Returns:
- the serialization view class, or
null
if none
-
getJsonEncoding
-