Hello i have a task to write a XML file exporter for composite objects of any kind.In this case,for the object Tree. The exporter should rely only on the annotations in the class definitions of the composite objects to produce the exported XML. The XML tags are should be defined within the How do i implement the Saver class with the method save(Object o) and the annotations classes?
public class Tree<T> {
private Tree<T>[] children = null;
private T value;
public Tree(T v, Tree<T>[] trees) { children = trees; value = v; }
public Tree(T v) { value = v; }
@SubElements(name="subnodes")
1
public Tree<T>[] getChildren() { return children; }
@ElementField(name="value")
public T getValue() { return value; }
}
so this program
Tree<String> t =
new Tree<String>("top",
new Tree[] {
new Tree("sub1"),
new Tree("sub2")
});
Saver s = new Saver();
String r = s.save(t);
System.out.println(r);
should output
<node value="top">
<subnodes>
<node value="sub1"/>
<node value="sub2"/>
</subnodes>
</node>
Aucun commentaire:
Enregistrer un commentaire