O'Reilly logo

Just Spring Integration by Madhusudhan Konda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required