my question is simple, but I can\'t find nothing about it.
I Have a list class and an entry class for XML Serialization:
@Root(name = \"entries\")
public
You can check for empty elements manually:
@Root(name = "entries")
@Convert(List.ListConverter.class) // Set the converter
public class List
{
@ElementList(required = false, entry = "entry", inline = true, empty = true)
private java.util.List entries;
public void add(Entry e)
{
// Just for testing
entries.add(e);
}
static class ListConverter implements Converter
{
@Override
public List read(InputNode node) throws Exception
{
List l = new List();
InputNode child = node.getNext("entry");
while( child != null)
{
if( child.isEmpty() == true ) // child is an empty tag
{
// Do something if entry is empty
}
else // child is not empty
{
Entry e = new Persister().read(Entry.class, child); // Let the Serializer read the Object
l.add(e);
}
child = node.getNext("entry");
}
return l;
}
@Override
public void write(OutputNode node, List value) throws Exception
{
// Not required for reading ...
throw new UnsupportedOperationException("Not supported yet.");
}
}
}
How to use:
Serializer ser = new Persister(new AnnotationStrategy()); // Set AnnotationStrategy here!
List l = ser.read(List.class, yourSourceHere);
Documentation: