user3808335
user3808335

Reputation: 183

Spring Integration Object To Map Transformer

I am using SI 4.0 and trying to use object-to-map-transformer as below

<integration:object-to-map-transformer input-channel="inputChannel" 
    output-channel="outChannel" >
</integration:object-to-map-transformer>

I am sending a object like Person class on the inputChannel. But the moment I fire my test it fails with following error

    Caused by: java.lang.IllegalStateException: Neither jackson-databind.jar, 
    nor jackson-mapper-asl.jar aren't presented in the classpath. at
org.springframework.integration.support.json.JacksonJsonUtils.<clinit>(JacksonJsonUtils.java:41)

I dont understand why it needs jackson. I looked at SI code and can see it needs Jackson class but why is this need - when I simply need to map a simple object to Map?

Thanks

Upvotes: 0

Views: 1258

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121282

The code to convert object to map looks like:

Map<String,Object> result = this.jsonObjectMapper.fromJson(this.jsonObjectMapper.toJson(payload), Map.class);

Since the out of the box implementation for the JsonObjectMapper is Jackson, it requires that the last one should be presented in the classpath.

We decided to use JSON notation for the Map presentation, since any object in JSON has map-based structure.

If you have another algorithm to do the same, the contribution is welcome!

Or you can simply implement your own Transformer with that logic and use it from generic <transformer>.

Upvotes: 1

Related Questions