JAXB 包装非集合字段

ata*_*man 5 java xml jaxb

给定一个 xml 文件,其中每个值都包装在它自己的元素中,如下所示:

<root>
    <type1>
        <foo>1</foo>
    </type1>
    <type2>
        <bar>2</bar>
    </type2>
</root>
Run Code Online (Sandbox Code Playgroud)

有没有一些简单的方法来绘制这个?喜欢@XmlElement("type1/foo")@XmlElementWrapper("type1") @XmlElement("foo")?据我所知,我需要创建一个相应的类模型(RootType1Type2),Type1并且Type2不提供任何附加值,而仅充当包装器。