Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-3647

Problem with different Request and Response Object at Json Transform

    XMLWordPrintable

    Details

    • Type: Support
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 4.2 M1
    • Component/s: HTTP Support
    • Labels:
      None

      Description

      Hello,

      i use Spring Integration Http with an outbound Gateway and try to connect to an other REST Service.

      For the Request and the Response, i use different POJO's.

      class Request {}
      
      class Response {}
      

      For my gateway, i use an Interface like that.

      interface ExternalRest {
        public Response callMethod(Request);
      }
      

      and my Integration Config looks like

      <int:gateway id="Testgateway"
      		service-interface="ExternalRest"
      		default-request-channel="RestObject">
      </int:gateway>
      
      <int-http:outbound-gateway
      		request-channel="RestJson" 
                      url="xxx"
      		http-method="POST" 
                      charset="UTF-8" 
                      reply-timeout="5000"
      		expected-response-type="java.lang.String" 
                      reply-channel="ReplyJson">
      </int-http:outbound-gateway>
      
      <int:object-to-json-transformer
      		input-channel="RestObject" 
                      output-channel="RestJson" 
                      content-type="application/json" />
      
      <int:json-to-object-transformer
      		input-channel="ReplyJson" />
      

      and my model is calling this service.

      @Autowired
      ExternalRest restService;
      
      Request request = new Request();
      
      Response response = restService.callMethod(request);
      

      The problem is, that the object-to-json-transformer add the header "json_TypeId_=class Request" and the json-to-object-transformer try's to create the wrong object with the error

      Unrecognized field "name" (class Request)
      

      For this case, it's easy to change the transformer to:

      <int:json-to-object-transformer
      		input-channel="ReplyJson" type="Response"/>
      

      and it's works, but i've a lot of calls with different ResponseObjects.

      It is possible to make the Transformer more flexible or how can i hook me in the ConversionService for making an fallback converter.

      Because in the transform, i don't get the correct return type from the gateway. The ConversionService has it in the convert method.

      Thanks for you help
      Marcel

        Attachments

          Activity

            People

            Assignee:
            abilan Artem Bilan
            Reporter:
            malburg Marcel Alburg
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: