Search code examples
spring-integrationspring-restcontroller

Spring-Integration Issue with json-to-object-transformer 'json' argument must be an instance of: [class java.lang.String, class


I have spring integration 5.0.4.RELEASE related issue.

I am getting error as below: java.lang.IllegalArgumentException: 'json' argument must be an instance of: [class java.lang.String, class [B

when I try to implement the below code:

    <int:header-enricher input-channel="xResponseChannel">
    <int:header name="expectedResponseType">
        <int-groovy:script>
            <![CDATA[
                new ParameterizedTypeReference<List<x.y.z.model.Film>>() {}
            ]]>
        </int-groovy:script>
    </int:header>
</int:header-enricher>

<int:chain input-channel="xRequestChannel">
    <int-http:outbound-gateway url="http://localhost:8084/films"
         http-method="GET"  expected-response-type-expression="headers[expectedResponseType]" />
    <int:json-to-object-transformer
        type="x.y.z.model.Film[]" />
    <int:service-activator ref="restResponseHandler" />
    <int-stream:stdout-channel-adapter
        id="consoleOut" append-newline="true" />
</int:chain>

Solution

  • The transformer only supports String, byte[], File, URL, InputStream and Reader.

    Since you've already set the expected response type on the HTTP adapter, it will already have been converted, so you don't need the transformer.