public class ObjectToJsonTransformer extends AbstractTransformer
Since version 3.0, adds headers to represent the object types that were mapped from (including one level of container and Map content types). These headers are compatible with the Spring AMQP Json type mapper such that messages mapped or converted by either technology are compatible. One difference, however, is the Spring AMQP converter, when converting to JSON, sets the header types to the class name. This transformer sets the header types to the class itself.
The compatibility is achieved because, when mapping the Spring Integration
message in the outbound endpoint (via the DefaultAmqpHeaderMapper
), the
classes are converted to String at that time.
Note: the first element of container/map types are used to determine the
container/map content types. If the first element is null, the type is set to
Object
.
Modifier and Type | Class and Description |
---|---|
static class |
ObjectToJsonTransformer.ResultType |
Modifier and Type | Field and Description |
---|---|
static String |
JSON_CONTENT_TYPE |
EXPRESSION_PARSER, logger
Constructor and Description |
---|
ObjectToJsonTransformer() |
ObjectToJsonTransformer(JsonObjectMapper<?,?> jsonObjectMapper) |
ObjectToJsonTransformer(JsonObjectMapper<?,?> jsonObjectMapper,
ObjectToJsonTransformer.ResultType resultType) |
ObjectToJsonTransformer(ObjectToJsonTransformer.ResultType resultType) |
Modifier and Type | Method and Description |
---|---|
protected Object |
doTransform(Message<?> message)
Subclasses must implement this method to provide the transformation
logic.
|
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
void |
setContentType(String contentType)
Sets the content-type header value
|
transform
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, onInit, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
public static final String JSON_CONTENT_TYPE
public ObjectToJsonTransformer()
public ObjectToJsonTransformer(JsonObjectMapper<?,?> jsonObjectMapper)
public ObjectToJsonTransformer(ObjectToJsonTransformer.ResultType resultType)
public ObjectToJsonTransformer(JsonObjectMapper<?,?> jsonObjectMapper, ObjectToJsonTransformer.ResultType resultType)
public void setContentType(String contentType)
contentType
- The content type.public String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class IntegrationObjectSupport
protected Object doTransform(Message<?> message)
AbstractTransformer
doTransform
in class AbstractTransformer
message
- The message.