gpt4 book ai didi

java - 带有 xml 负载的 Spring Boot Rest Controller

转载 作者:行者123 更新时间:2023-11-30 06:31:47 26 4
gpt4 key购买 nike

我正在使用使用 application/xml 数据类型的 Spring Boot Rest Controller 创建一个 Rest 服务。发送嵌套 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>

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

请求数据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] .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

最佳答案

您的应用程序在解析传入的 XML 时遇到问题,因为它认为它是 JSON。也许添加以下内容会有所帮助:

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

如果没有,你可以检查这个类似的问题 here .

关于java - 带有 xml 负载的 Spring Boot Rest Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45940582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com