2

I am having a rest service created using spring boot rest controller consuming application/xml datatype. When sending the nested xml it is not able to parse it. is it even possible? or i should go ahead with writing a new soap interface.

request payload

<requestData>
    <jvmCount>16</jvmCount>
    <maxAttampts>345</maxAttampts>
    <locationXpath>abd/adfd/bdc</locationXpath>
    <requestPayload>
            <userdetails>
        //variabe user data with different xml structure
            </userdetails>  
    </requestPayload>
</requestData>

controller

@PostMapping(value = "/soap", consumes=MediaType.APPLICATION_XML_VALUE, 
    produces=MediaType.APPLICATION_XML_VALUE)
@ResponseBody
public ResponseEntity<?> soapServiceClient(@Valid @RequestBody RequestData requestData, Errors errors) throws InterruptedException{
    logger.info(" ==== soapServiceClient - started"+requestData);
}

RequestData pojo

@XmlRootElement
public class RequestData{
    private int jvmCount;
    private String locationXpath;
    private int maxAttampts;
    private String requestPayload;
}

Exception

2017-08-29 18:54:41.667 WARN 13776 --- [nio-8181-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token

1
  • What do your request headers look like? You should have a "ContentType" specifying "application/xml" to indicate to your app the format of your request body. Commented Aug 29, 2017 at 13:41

1 Answer 1

1

Your app is having trouble parsing the incoming XML, because it thinks it's JSON. Maybe adding the following will help:

<groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
</dependency>

If not you can check this similar question here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.