Spring Rest Jackson XML / JSON问题

我有Rest控制器,该控制器同时使用XML / JSON和Jackson作为默认转换器。 PFB POJO。

@JacksonXmlRootElement(localName = "AsyncRegistrationResponse")
public class AsyncRegistrationResponse {

public AsyncRegistrationResponse() {
}

@JacksonXmlProperty(isAttribute = true,localName="RegistrationStep")
@JsonProperty("RegistrationStep")
   private String registrationStep;

@JsonProperty("TransactionId")
@JacksonXmlProperty(isAttribute = true,localName="TransactionId")
private String transactionId;

//Other properties
}  

它适用于XML,但是当我用JSON对象测试它时,它会填充NULL值。 PFB JSON

    {
  "AsyncRegistrationResponse": {
    "RegistrationStep": "RecordBuilding","TransactionId": "str1234","TransactionRefId": "str1234","SystemId": "str1234"}
   }

JSON POST仅在删除根级别 AsyncRegistrationResponse 元素时有效。由于我想使用根元素发布JSON数据 AsyncRegistrationResponse 我用谷歌搜索了解决方案,并获得了关于堆栈溢出的解决方案,如applicaiton.properties中的下一行所示。

spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true

在使用根元素 AsyncRegistrationResponse 启用UNWRAP_ROOT_VALUE JSON POST后,它开始工作,但引起了另一个问题。即使 我将XML输入的内容类型发布为“ application / xml”,但仍将输入视为JSON并抛出错误。

基本上我希望rest控制器能够同时使用XML / JSON,但是启用后

spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true 

它不适用于XML。如果禁用它,则JSON输入不适用于根级元素。任何解决方案。

wuzh166 回答:Spring Rest Jackson XML / JSON问题

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2873720.html

大家都在问