Class ObjectToJsonTransformer
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- ComponentSourceAware,- 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 SummaryNested Classes
- 
Field SummaryFieldsFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, logger
- 
Constructor SummaryConstructorsConstructorDescriptionObjectToJsonTransformer(JsonObjectMapper<?, ?> jsonObjectMapper) ObjectToJsonTransformer(JsonObjectMapper<?, ?> jsonObjectMapper, ObjectToJsonTransformer.ResultType resultType) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected ObjectdoTransform(Message<?> message) Subclasses must implement this method to provide the transformation logic.Subclasses may implement this method to provide component type information.voidsetContentType(String contentType) Set the content-type header value.Methods inherited from class org.springframework.integration.transformer.AbstractTransformertransformMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, onInit, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
- 
Field Details- 
JSON_CONTENT_TYPE- See Also:
 
 
- 
- 
Constructor Details- 
ObjectToJsonTransformerpublic ObjectToJsonTransformer()
- 
ObjectToJsonTransformer
- 
ObjectToJsonTransformer
- 
ObjectToJsonTransformerpublic ObjectToJsonTransformer(JsonObjectMapper<?, ?> jsonObjectMapper, ObjectToJsonTransformer.ResultType resultType) 
 
- 
- 
Method Details- 
setContentTypeSet the content-type header value.- Parameters:
- contentType- The content type.
 
- 
getComponentTypeDescription copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
- getComponentTypein interface- NamedComponent
- Overrides:
- getComponentTypein class- IntegrationObjectSupport
 
- 
doTransformDescription copied from class:AbstractTransformerSubclasses 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:
- doTransformin class- AbstractTransformer
- Parameters:
- message- The message.
- Returns:
- The result of the transformation.
 
 
-