I am using an integration flow to call a RESTful web service as follows:
@Bean
IntegrationFlow flow() throws Exception {
return IntegrationFlows.from("inputChannel")
.handle(Http.outboundGateway("http://provider1.com/...")
.httpMethod(HttpMethod.GET)
.expectedResponseType(ItemDTO[].class))
.get();
}
In fact, the code above works perfectly. As I understand from the documentation, Spring integration's http outbound-gateway uses an instance of RestTemplate to convert the Http response body to an array of ItemDTO
s.
Let us now consider the following code:
@Bean
IntegrationFlow flow() throws Exception {
return IntegrationFlows.from("inputChannel")
.handle(Http.outboundGateway("http://provider2.com/...")
.httpMethod(HttpMethod.GET)
.expectedResponseType(String.class))
.<String,String>transform(m -> sirenToHal(m))
.transform(Transformers.fromJson(ItemDTO[].class))
.get();
}
In this case, the Http response body is converted into a String, which is passed to a transformer (e.g. in my actual project, I use JOLT to convert from a siren document to a HAL -- JSON resource representations). Then, I instantiate a transformer to handle the mapping of JSON to java objects. Suprisingly, the code above fails (e.g. in my project, the transformer throws a UnrecognizedPropertyException
).
The reason of the failure seems to be that the Object mapper used by the transformer is not configured in the same way as the RestTemplate. I wonder why the transformer does not use the same ObjectMapper as the instance of RestTemplate or, at least, why they do not use the same configuration (i.e. Spring boot's global configuration). Anyway, is there anyway configure the ObjectMapper to be used by the transformer?
Update
I found out how to configure the tranformer's object mapper.
First, we create and configure an instance of Jackson's ObjectMapper, as follows:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// + any other additional configuration setting
Then, we instantiate the transformer as follows (replacing the corresponding line in the code above):
.transform(Transformers.fromJson(ItemDTO[].class, new Jackson2JsonObjectMapper(mapper)))
I still think the ObjectMapper used by the transformer should take Spring boot's global configuration.
() {})`. I think this would simplify, for instance, the aggregation of message groups as in my example [here](http://stackoverflow.com/questions/36742888/spring-integration-java-dsl-configuration-of-aggregator).
– user3329862 Apr 21 '16 at 15:02