vashishth
vashishth

Reputation: 3380

springboot rest controller with xml payload

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

Upvotes: 2

Views: 4650

Answers (1)

Nikolai Tenev
Nikolai Tenev

Reputation: 475

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.

Upvotes: 1

Related Questions