Re: [Simple-support] Serializing inline list of "simple" elements
Brought to you by:
niallg
|
From: Timo R. <cr...@ol...> - 2008-05-28 07:02:06
|
Hi Kevin,
the following code produces exactly the result you desire:
----------------------------
public class SimpleXMLTest {
@Root
private class Event {
@Text
private String text;
public Event( String text ) {
this.text = text;
}
public String getText() {
return text;
}
}
@Root( name = "events" )
private class EventList {
@ElementList( inline = true )
private List< Event > events = new ArrayList< Event >();
public List< Event > getEvents() {
return events;
}
}
public SimpleXMLTest() throws Exception {
EventList list = new EventList();
list.getEvents().add( new Event( "foo" ) );
list.getEvents().add( new Event( "bar" ) );
Serializer serializer = new Persister();
serializer.write( list, System.out );
}
public static void main( String[] args ) throws Exception {
new SimpleXMLTest();
}
}
----------------------------
Please have a look at the "name" and "inline" annotation parameters -
these control the "format" of the XML, so it looks like your XML
example.
Hope that helps
Regards,
Timo
|