public class EmbeddedJsonHeadersMessageMapper extends java.lang.Object implements BytesMessageMapper
byte[] payloads, if rendered as JSON, Jackson
performs Base64 conversion on the bytes. If the rawBytes
property is true (default), the result has the form
<headersLen><headers><payloadLen><payload>; with the headers
rendered in JSON and the payload unchanged.
By default, all headers are included; you can provide simple patterns to specify a subset of headers.
If neither expected format is detected, or an error occurs during conversion, the
payload of the message is the original byte[].
IMPORTANT
The default object mapper will only deserialize classes in certain packages.
"java.util",
"java.lang",
"org.springframework.messaging.support",
"org.springframework.integration.support",
"org.springframework.integration.message",
"org.springframework.integration.store"
To add more packages, create an object mapper using
JacksonJsonUtils.messagingAwareMapper(String...).
A constructor is provided allowing the provision of such a configured object mapper.
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
EmbeddedJsonHeadersMessageMapper()
Construct an instance that embeds all headers, using the default
JSON Object mapper.
|
EmbeddedJsonHeadersMessageMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Construct an instance that embeds all headers, using the
supplied JSON object mapper.
|
EmbeddedJsonHeadersMessageMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
java.lang.String... headerPatterns)
Construct an instance that embeds headers matching the supplied patterns using the
supplied JSON object mapper.
|
EmbeddedJsonHeadersMessageMapper(java.lang.String... headerPatterns)
Construct an instance that embeds headers matching the supplied patterns, using
the default JSON object mapper.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
fromMessage(org.springframework.messaging.Message<?> message) |
java.util.Collection<java.lang.String> |
getHeaderPatterns() |
void |
setCaseSensitive(boolean caseSensitive)
Set to true to make the header name pattern match case sensitive.
|
void |
setRawBytes(boolean rawBytes)
For messages with
byte[] payloads, if rendered as JSON, Jackson performs
Base64 conversion on the bytes. |
org.springframework.messaging.Message<?> |
toMessage(byte[] bytes,
java.util.Map<java.lang.String,java.lang.Object> headers)
Convert a provided object to the
Message
and supply with headers if necessary and provided. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waittoMessagepublic EmbeddedJsonHeadersMessageMapper()
public EmbeddedJsonHeadersMessageMapper(java.lang.String... headerPatterns)
headerPatterns - the patterns.PatternMatchUtils.smartMatch(String, String...)public EmbeddedJsonHeadersMessageMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
objectMapper - the object mapper.public EmbeddedJsonHeadersMessageMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
java.lang.String... headerPatterns)
objectMapper - the object mapper.headerPatterns - the patterns.public void setRawBytes(boolean rawBytes)
byte[] payloads, if rendered as JSON, Jackson performs
Base64 conversion on the bytes. If this property is true (default), the result has
the form <headersLen><headers><payloadLen><payload>; with
the headers rendered in JSON and the payload unchanged. Set to false to render
the bytes as base64.rawBytes - false to encode as base64.public void setCaseSensitive(boolean caseSensitive)
caseSensitive - true to make case sensitive.public java.util.Collection<java.lang.String> getHeaderPatterns()
public byte[] fromMessage(org.springframework.messaging.Message<?> message)
throws java.lang.Exception
fromMessage in interface OutboundMessageMapper<byte[]>java.lang.Exceptionpublic org.springframework.messaging.Message<?> toMessage(byte[] bytes,
@Nullable
java.util.Map<java.lang.String,java.lang.Object> headers)
InboundMessageMapperMessage
and supply with headers if necessary and provided.toMessage in interface InboundMessageMapper<byte[]>bytes - the object for message payload or some other conversion logicheaders - additional headers for building message. Can be null