Class ObjectToJsonTransformer
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ExpressionCapable
,NamedComponent
,GenericTransformer<Message<?>,Message<?>>
,Transformer
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
.
- Since:
- 2.0
- Author:
- Mark Fisher, James Carr, Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ObjectToJsonTransformer.ResultType
-
Field Summary
Fields Modifier and Type Field Description static String
JSON_CONTENT_TYPE
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
Constructors Constructor Description ObjectToJsonTransformer()
ObjectToJsonTransformer(ObjectToJsonTransformer.ResultType resultType)
ObjectToJsonTransformer(JsonObjectMapper<?,?> jsonObjectMapper)
ObjectToJsonTransformer(JsonObjectMapper<?,?> jsonObjectMapper, ObjectToJsonTransformer.ResultType resultType)
-
Method Summary
Modifier and Type Method 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 valueMethods inherited from class org.springframework.integration.transformer.AbstractTransformer
transform
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
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
-
Field Details
-
JSON_CONTENT_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Details
-
ObjectToJsonTransformer
public ObjectToJsonTransformer() -
ObjectToJsonTransformer
-
ObjectToJsonTransformer
-
ObjectToJsonTransformer
public ObjectToJsonTransformer(JsonObjectMapper<?,?> jsonObjectMapper, ObjectToJsonTransformer.ResultType resultType)
-
-
Method Details
-
setContentType
Sets the content-type header value- Parameters:
contentType
- The content type.
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classIntegrationObjectSupport
-
doTransform
Description copied from class:AbstractTransformer
Subclasses must implement this method to provide the transformation logic. If the return value is itself a Message, it will be used as the result. Otherwise, any non-null return value will be used as the payload of the result Message.- Specified by:
doTransform
in classAbstractTransformer
- Parameters:
message
- The message.- Returns:
- The result of the transformation.
-