【问题标题】:springboot rest controller with xml payload带有xml有效负载的spring boot rest控制器
【发布时间】: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


【解决方案1】:

您的应用无法解析传入的 XML,因为它认为它是 JSON。 也许添加以下内容会有所帮助:

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

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

【讨论】:

    猜你喜欢
    • 2020-03-24
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 2017-12-12
    • 2017-05-04
    • 2018-01-26
    • 2016-01-29
    • 1970-01-01
    相关资源
    最近更新 更多