Class ObjectToJsonTransformer
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ExpressionCapable
,GenericTransformer<Message<?>,
,Message<?>> NamedComponent
,Transformer
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
-
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionObjectToJsonTransformer
(JsonObjectMapper<?, ?> jsonObjectMapper) ObjectToJsonTransformer
(JsonObjectMapper<?, ?> jsonObjectMapper, ObjectToJsonTransformer.ResultType resultType) -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
doTransform
(Message<?> message) Subclasses must implement this method to provide the transformation logic.Subclasses may implement this method to provide component type information.void
setContentType
(String contentType) Set the content-type header value.Methods 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, getMessageBuilderFactory, getTaskScheduler, isInitialized, onInit, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Field Details
-
JSON_CONTENT_TYPE
- See Also:
-
-
Constructor Details
-
ObjectToJsonTransformer
public ObjectToJsonTransformer() -
ObjectToJsonTransformer
-
ObjectToJsonTransformer
-
ObjectToJsonTransformer
public ObjectToJsonTransformer(JsonObjectMapper<?, ?> jsonObjectMapper, ObjectToJsonTransformer.ResultType resultType)
-
-
Method Details
-
setContentType
Set 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.
-