JAXB无限数据结构,递归绑定? [英] JAXB endless data structure, recursive binding?

查看:150
本文介绍了JAXB无限数据结构,递归绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始项目之前,我想在这里得到一个很小的头。



如果我有这样的结构:

 < root> ; 
< a>
< a>
< a>
< a>
< a />
< / a>
< / a>
< / a>
< a>
< / a>
< / a>



一个元素可以容纳一个元素,这是无休止的。



写一个A类,然后给它一个列表作为成员?那么JAXB会自动做魔术吗?或者这种结构是不可能的?

解决方案

是的,你可以有以下几点:

  @XmlAccessorType(XmlAccessType.FIELD)
public class A {

private List< A>一个;

}

而您的 JAXB(JSR-222) 实现将正确组织。



相关示例




sBefore starting a project I wanted to get a short heads up here.

If I have a structure like this:

<root>
<a>
    <a>
        <a>
            <a>
                <a/>
            </a>
        </a>
    </a>
    <a>
    </a>
</a>

The a element can hold a elements and this endlessly deep.

Do I just write a class A and then give it a List as a member? JAXB does the magic automatically then? Or is this structure not possible?

解决方案

Yes you can have the following:

@XmlAccessorType(XmlAccessType.FIELD)
public class A {

    private List<A> a;

}

And your JAXB (JSR-222) implementation will marshal it correctly.

Related Example

这篇关于JAXB无限数据结构,递归绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆