2017-08-29 65 views
1

springboot其餘控制器使用彈簧引導其餘控制器消費應用程序/ XML數據類型創建的。發送嵌套的xml時,它無法解析它。它甚至有可能嗎?或者我應該繼續編寫一個新的soap接口。與我有一個休息服務XML有效載荷

請求有效載荷

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

控制器

@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); 
} 

POJO的RequestData

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

除ion

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

+0

你的請求標題是什麼樣的?您應該有一個指定「application/xml」的「ContentType」來向您的應用程序指示請求主體的格式。 – Matt

回答

1

您的應用程序在解析傳入的XML時遇到問題,因爲它認爲它是JSON。 也許添加以下幫助:

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

如果沒有,你可以檢查此類似的問題here