Built-In Transformers

Framework provides a couple of built-in transformers so you don’t have to create them for simple cases such as converting an Object to String, Map, or JSON formats. The integration namespace supports these transformers.

String Transformers

Using the Object to String transformer is easy—all we have to do is define one in our bean’s XML using the object-to-string-transformer element. The following snippet shows the definition:

<int:object-to-string-transformer
  input-channel="in-channel" 
  output-channel="stdout">
</int:object-to-string-transformer>

<int-stream:stdout-channel-adapter id="stdout"/>

So, any POJOs (Plain Old Java Objects) appearing in the trades-in-channel will automatically be converted to string without intervention by custom transformers. Note that we do not provide reference to any transformer in the above config definition. In fact, the object-to-string-transformer element will not take the ref attribute. The payload at the receiver’s end will always be a toString() of the POJO. In the above example, the payload is written to the stdout using the stdout-channel-adapter. So, make sure your published POJO has overridden the toString() method, or else you will see gibberish as your String payload (such as com.madhusudhan.jsi.domain.Trade@309ff0a8).

Map Transformers

If you need to convert the POJO to a name-value pair of Map, you can use the Object to Map transformer. It is represented by the object-to-map-transformer element that takes the payload from ...

Get Just Spring Integration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.