Announcement Announcement Module
No announcement yet.
Spring Integration and JSON Payload Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration and JSON Payload

    I have configured my spring integration with http-gatway. Depending on the a header value "Request-type", I will route to either JSON-to-object or xml marshaller. This work perfectly if the "Content-Type" value is "text/xml" for both json and xml payload.

    When I change the "Content-Type" to "application/json" as my payload is json, I got the below error. Below is the exception. Can you please let me know, why I am facing this exception and whether the "Content-Type" value should be always "text/xml" for json payload also?

    org.springframework.integration.transformer.Messag eTransformationException: failed to transform message

    Caused by: java.lang.ClassCastException: [B cannot be cast to java.lang.String
    at org.springframework.integration.json.JsonToObjectT ransformer.transformPayload(JsonToObjectTransforme
    at org.springframework.integration.transformer.Abstra ctPayloadTransformer.doTransform(AbstractPayloadTr
    at org.springframework.integration.transformer.Abstra ctTransformer.transform( 3)


  • #2
    Set the request-payload-type to "java.lang.String".

    Here's why...

    	 * Specify the type of payload to be generated when the inbound HTTP request content is read by the
    	 * {@link HttpMessageConverter}s. By default this value is null which means at runtime any "text" Content-Type will
    	 * result in String while all others default to <code>byte[].class</code>.
    	public void setRequestPayloadType(Class<?> requestPayloadType) {
    		this.requestPayloadType = requestPayloadType;
    Please use [ ] around code (not < >).