【问题标题】:Can JAXB unmarshall XML according to my object structure?JAXB 可以根据我的对象结构解组 XML 吗?
【发布时间】:2012-08-07 00:45:16
【问题描述】:

我的对象结构与 XML 结构没有太大的不同。只想为一个元素更改它。 我有这样的 XML 结构

<Parent>
    <Child1></Child1>
    <Child2></Child2>
    <Child3></Child3>
    <Child3></Child3>
    <Child3></Child3>
</Parent>

它的等效 JAXB 类看起来像这样

    @XmlRootElement(name="Parent")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "Parent_Type")
    public class Parent {
        protected List<Child1Type> child1;
        protected List<Child2Type> child2;
        protected List<Child3Type> child3;
    }

但根据数据库模型要求,我希望 Child1 下的 Child3 列表。这将帮助我使用 Hibernate 保存 XML。

public class Child1 {
    protected List<Child3Type> child3;
}

如何使用 JAXB 对其进行配置? 还是我应该使用afterUnmarshal 手动执行?

【问题讨论】:

  • 你可能对@XmlIDREF感兴趣:blog.bdoughan.com/2010/10/…
  • @BlaiseDoughan 我刚刚更新了预期的对象模型。这里 Child1 需要 Child3 的列表。抱歉复制粘贴错误。

标签: jaxb unmarshalling


【解决方案1】:

我认为这不可能满足我的要求。我在 afterUnmarshal() 方法下编写了一个转换逻辑,可以根据我的需要将常规解组转换为转换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 2014-05-20
    • 2014-10-27
    相关资源
    最近更新 更多