Class EmbeddedHeadersJsonMessageMapper
java.lang.Object
org.springframework.integration.support.json.EmbeddedHeadersJsonMessageMapper
- All Implemented Interfaces:
BytesMessageMapper, InboundMessageMapper<byte[]>, OutboundMessageMapper<byte[]>
For outbound messages, uses a message-aware Jackson JSON mapper to render the message
as JSON. For messages with
byte[] payloads, if rendered as JSON, Jackson
performs Base64 conversion on the bytes. If payload is byte[] and
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.
Otherwise, the message is fully serialized and deserialized with Jackson JSON mapper.
By default, embed no headers apart from the standard MessageHeaders.ID,
MessageHeaders.TIMESTAMP and MessageHeaders.CONTENT_TYPE headers;
always embed those (when present) to restore them on the receiving side.
Provide simple patterns to specify additional headers to embed.
If neither expected format is detected, nor an error occurs during conversion, the
payload of the message is the original byte[].
IMPORTANT
The default JSON 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",
"org.springframework.integration.history",
"org.springframework.integration.handler"
To add more packages, create an JSON mapper using
JacksonMessagingUtils.messagingAwareMapper(String...).
A constructor is provided allowing the provision of such a configured JSON mapper.
- Since:
- 7.0
- Author:
- Jooyoung Pyoung, Glenn Renfro
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an instance that embeds no headers besides the standardMessageHeaders.ID,MessageHeaders.TIMESTAMPandMessageHeaders.CONTENT_TYPE; use the default JSON Object mapper.EmbeddedHeadersJsonMessageMapper(String... headerPatterns) Construct an instance that embeds headers matching the supplied patterns; use the default JSON object mapper.EmbeddedHeadersJsonMessageMapper(tools.jackson.databind.json.JsonMapper jsonMapper) Construct an instance that embeds no headers besides the standardMessageHeaders.ID,MessageHeaders.TIMESTAMPandMessageHeaders.CONTENT_TYPE; use the supplied JSON object mapper.EmbeddedHeadersJsonMessageMapper(tools.jackson.databind.json.JsonMapper jsonMapper, String... headerPatterns) Construct an instance that embeds headers matching the supplied patterns; use the supplied JSON object mapper. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]fromMessage(Message<?> message) voidsetCaseSensitive(boolean caseSensitive) Set to true to make the header name pattern match case-sensitive.voidsetRawBytes(boolean rawBytes) For messages withbyte[]payloads, if rendered as JSON, Jackson performs Base64 conversion on the bytes.Message<?> Convert a provided object to theMessageand supply with headers if necessary and provided.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BytesMessageMapper
toMessage
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
EmbeddedHeadersJsonMessageMapper
public EmbeddedHeadersJsonMessageMapper()Construct an instance that embeds no headers besides the standardMessageHeaders.ID,MessageHeaders.TIMESTAMPandMessageHeaders.CONTENT_TYPE; use the default JSON Object mapper. -
EmbeddedHeadersJsonMessageMapper
Construct an instance that embeds headers matching the supplied patterns; use the default JSON object mapper. Always embed the standardMessageHeaders.ID,MessageHeaders.TIMESTAMPandMessageHeaders.CONTENT_TYPEheaders (when present) regardless of the supplied patterns.- Parameters:
headerPatterns- the patterns.- See Also:
-
EmbeddedHeadersJsonMessageMapper
public EmbeddedHeadersJsonMessageMapper(tools.jackson.databind.json.JsonMapper jsonMapper) Construct an instance that embeds no headers besides the standardMessageHeaders.ID,MessageHeaders.TIMESTAMPandMessageHeaders.CONTENT_TYPE; use the supplied JSON object mapper.- Parameters:
jsonMapper- the JSON mapper.
-
EmbeddedHeadersJsonMessageMapper
public EmbeddedHeadersJsonMessageMapper(tools.jackson.databind.json.JsonMapper jsonMapper, String... headerPatterns) Construct an instance that embeds headers matching the supplied patterns; use the supplied JSON object mapper. Always embed the standardMessageHeaders.ID,MessageHeaders.TIMESTAMPandMessageHeaders.CONTENT_TYPEheaders (when present) regardless of the supplied patterns.- Parameters:
jsonMapper- the JSON mapper.headerPatterns- the patterns.
-
-
Method Details
-
setRawBytes
public void setRawBytes(boolean rawBytes) For messages withbyte[]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 tofalseto render the bytes as base64.- Parameters:
rawBytes- false to encode as base64.
-
setCaseSensitive
public void setCaseSensitive(boolean caseSensitive) Set to true to make the header name pattern match case-sensitive. Default false.- Parameters:
caseSensitive- true to make case-sensitive.
-
getHeaderPatterns
-
fromMessage
- Specified by:
fromMessagein interfaceBytesMessageMapper- Specified by:
fromMessagein interfaceOutboundMessageMapper<byte[]>
-
toMessage
Description copied from interface:InboundMessageMapperConvert a provided object to theMessageand supply with headers if necessary and provided.- Specified by:
toMessagein interfaceBytesMessageMapper- Specified by:
toMessagein interfaceInboundMessageMapper<byte[]>- Parameters:
bytes- the object for message payload or some other conversion logicheaders- additional headers for building message. Can be null- Returns:
- the message as a result of mapping
-