Saturday, 27 December 2014

XML serialization reference - duplicate



[Java or C#] I have some problem with serialization. How not to duplicate all the information about the object and use only reference?


Sample classes:



class Author {
public String id;
public String name;
}

class Book {
public String id;
public Author author;
public String title;
}


And I have to format the output file like here:



<store>
<authors>
<author id="PK">
<name>Philip Kindred</name>
</author>
</authors>

<books>
<book id="u1">
<author>PK</author> <!-- use only ID -->
<title>Ubik</title>
</book>
</books>
</store>

No comments:

Post a Comment