反序列化包含 XML 字符串的 XML 属性

问题描述

我正在使用第三方 Web API,该 API 会返回一些 XML,其中的属性包含一些序列化的 XML。

我想使用 Jackson 将此响应反序列化到 POJO,但我似乎无法找到如何注释我的类以使其工作。

这是一个与接收到的响应结构相匹配的虚拟示例,在 nested 属性中带有字符串化的 XML:

<MainElement
  foo="Bar"
  nested="&lt;nested baz=&quot;value&quot; /&gt;"
><MainElement/>

我定义的类将如下所示:

// Imports

@JacksonXmlRootElement
public class MainElement {
  @JacksonXmlProperty(isAttribute = true)
  private String foo;

  @JacksonXmlProperty(isAttribute = true)
  private nested nested;

  // Getters & Setters
}
// Imports

@JacksonXmlRootElement(localName = "nested")
public class nested {
  @JacksonXmlProperty(isAttribute = true)
  private String baz;

  // Getters & Setters
}

唉,这个配置似乎不起作用,并从杰克逊那里引发了一个MismatchedInputException,本质上是这样的:

Cannot construct instance of `com.example.nested` (although at least one Creator exists):
no String-argument constructor/factory method to deserialize from String value ('<nested baz="value" />')

在这里遗漏了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)