Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB endless data structure, recursive binding?

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?

like image 779
Franz Kafka Avatar asked Jan 29 '26 14:01

Franz Kafka


1 Answers

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

  • How to unmarshal xml message with bad parent/child model
like image 59
bdoughan Avatar answered Feb 01 '26 03:02

bdoughan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!