开发者

Can I marshal my own data structures with JAXB?

开发者 https://www.devze.com 2023-01-25 03:12 出处:网络
I am using my own iterable structures - various BinaryTrees. Can I simply marshal them? It\'s quite easy to marshal f.e. java.util.List implementations, but in my case, it\'s absolutely unacceptable.

I am using my own iterable structures - various BinaryTrees. Can I simply marshal them? It's quite easy to marshal f.e. java.util.List implementations, but in my case, it's absolutely unacceptable. I need to use my own structures, with no internal containers whatsoever - only memory chains (root.leftson.rightson etc.)

In other words, is it possible to marshall structure like:

class BinaryTree<T> implements Iterable<T> ?

Edit: Structure is supposed to look like (for BinaryTree<Person>):

<persons>
 <person>
   <name>John</name开发者_Go百科>
   <surname>Black</name>
 </person>
 <person>
   <name>Joe</name>
   <surname>Blue</name>
 </person>
</persons>

So when I add annotation to my structure like:

@XmlElement
private BinaryTree<Person> persons = new BinaryTree<Person>();
public BinaryTree<Person> getPersons() { return persons; }

,it just creates empty element like <persons />. I also tried @XmlElementWrapper annotations, but it won't take custom structure (must be collection or something similar). It would be nice to have like @IterableElement or what :)


There is a guide on how to do your own marshalling methods in the javadoc of XMLAdapter. This way, using the @XMLJavaAdapter annotation, you can define exactly how you want to marshal your class.

0

精彩评论

暂无评论...
验证码 换一张
取 消