Anurag Sharma
Anurag Sharma

Reputation: 2605

JAXB serialization: Option to have a reference to inner objects

We are serializing a large number of objects. Some objects have attributes as list of objects.

I found an option in Texo serializer where such list of objects are saved as references and a lot of space is saved rather than showing same object multiple times. eg shown below:

<target:LogicalFact id="6022" version="28"
created="2014-12-01T15:53:59.000+0000"       
logicalColumns="#/16651 #/10549 #/17142 #/16898 #/16542 #/16551 #/16832 #/16623 #/17230 #/16645 #/16393 #/16968 #/16575 #/17179 #/17195 #/16717 #/16636 #/16560 #/16410 #/16814 #/16610 #/16691 #/17173 #/16705 #/16838"/> 

In above example, all logical columns are references. This saves space by avoiding duplicate information. Is there any such option available with JAXB serializer.

Upvotes: 0

Views: 78

Answers (1)

lexicore
lexicore

Reputation: 43671

You are most probably interested in @XmlIDand @XmlIDREF which allow to reference objects.

@XmlAccessorType(XmlAccessType.FIELD)
public class Employee {

    @XmlID
    @XmlAttribute
    private String id;

    @XmlAttribute
    private String name;

    @XmlIDREF
    private Employee manager;

    @XmlIDREF
    @XmlList
    private List<Employee> reports;

    public Employee() {
        reports = new ArrayList<Employee>();
    }

}

Please see this the following post by Blaise Doughan:

http://blog.bdoughan.com/2010/10/jaxb-and-shared-references-xmlid-and.html

The code snippet above is taken from this post.

Upvotes: 1

Related Questions