如何在解组期间强制 JAXB/Moxy 遵循顺序?

问题描述

我对 JAXB/Moxy 很陌生,正在尝试实施 Marshalling and Unmarshalling。经过大量搜索和阅读文章后,我知道我们可以使用 proporder 因此封送遵循顺序,但如何确保 unmarshalling 遵循顺序?

以下是我拥有的 Customer POJO:

@XmlRootElement(name = "Customer")
@XmlType(name = "Customer",propOrder = {"name","others"})
@XmlAccessorType(XmlAccesstype.FIELD)
@Getter
@Setter
@NoArgsConstructor
public class Customer {

  private String name;

  @XmlPath(".")
  @XmlJavaTypeAdapter(TestAdapter.class)
  @JsonSerialize(using = CustomExtensionsSerializer.class)
  private Map<String,Object> others = new HashMap<>();

  @JsonAnySetter
  public void setothers(String key,Object value) {
    others.put(key,value);
  }

  public Customer xmlSupport() {
    return this;
  }
}

虽然 unmarshalling XML 文件中的所有 XML Node and data 自动填充到 Map<String,Object> others 字段中,因此当我尝试从 {{ 创建 JSON 时1}} 我得到了 unmarshaled 中的所有字段:

others

为了避免这种情况,我想确保我的 { "name" : "","others" : { "name" : "MY","google:sub" : "bye" } } 遵循顺序并首先填充字段 unmarshaller,然后将所有不匹配的字段填充到我的 name

请注意:在 Map<String,Object> 期间我需要 @XmlPath("."),因为我想跳过 marshaling 节点但保留其中的值。所以我无法删除它。

任何帮助或输入将不胜感激。

解决方法

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

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

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