Search code examples
jsonspring-integrationspring-json

JSON as String in Spring Integration


I use a int:gateway to bring in a json String into a int:channel. When I print this json String using <int-stream:stdout-channel-adapter/> (or even if I print it inside a service activator attached to int:channel) it is printing key/value pairs with = instead of : For example -> GenericMessage [payload={id=1596096, key=SOME_KEY, address={first_name=John, last_name=...... To solve this problem I have to use a <int:object-to-json-transformer />

What is the best way to work with raw JSON? My use case is to do a JSON to JSON transformation (also using a splitter).


Solution

  • Your printed payload looks more like a Map or some POJO, so probably before that <int-stream:stdout-channel-adapter/> you have a step transforming an incoming string into that object.

    For raw JSON we suggest to deal with a #jsonpath() SpEL-function: https://docs.spring.io/spring-integration/docs/current/reference/html/spel.html#built-in-spel-functions