Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration and JSON Payload Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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?

    <CODE>
    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 r.java:30)
    at org.springframework.integration.transformer.Abstra ctPayloadTransformer.doTransform(AbstractPayloadTr ansformer.java:33)
    at org.springframework.integration.transformer.Abstra ctTransformer.transform(AbstractTransformer.java:3 3)

    </CODE>

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

    Here's why...

    Code:
    	/**
    	 * 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 < >).

    Comment

    Working...
    X