【发布时间】:2018-02-06 23:56:16
【问题描述】:
我正在使用使用应用程序/xml 数据类型的 Spring Boot 休息控制器创建休息服务。发送嵌套的 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
@XmlRootElement
public class RequestData{
private int jvmCount;
private String locationXpath;
private int maxAttampts;
private String requestPayload;
}
例外
2017-08-29 18:54:41.667 WARN 13776 --- [nio-8181-exec-1] .wsmsDefaultHandlerExceptionResolver:已解决由处理程序执行引起的异常:org.springframework.http.converter.HttpMessageNotReadableException:JSON 解析错误:无法从 START_OBJECT 令牌中反序列化 java.lang.String 的实例;嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize an instance of java.lang.String out of START_OBJECT token
【问题讨论】:
-
您的请求标头是什么样的?您应该有一个“ContentType”,指定“application/xml”,以向您的应用指示您的请求正文的格式。
标签: java spring-boot spring-restcontroller