Class ObjectToJsonTransformer

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ExpressionCapable, NamedComponent, GenericTransformer<Message<?>,​Message<?>>, Transformer

public class ObjectToJsonTransformer
extends AbstractTransformer
Transformer implementation that converts a payload instance into a JSON string representation. By default this transformer uses JsonObjectMapperProvider factory to get an instance of a Jackson or Jackson 2 JSON-processor JsonObjectMapper implementation depending on the jackson-databind or jackson-mapper-asl libs on the classpath. Any other JsonObjectMapper implementation can be provided.

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