How can I set the name of the class xml by constructor?
- by spderosso
Hi,
I want to be able to do something like this:
@Root(name="events")
class XMLEvents {
@ElementList(inline=true)
ArrayList<XMLEvent> events = Lists.newArrayList();
XMLEvents(){
...
events.add(new XMLEvent(time, type, professorP));
events.add(new XMLEvent(time, type, student));
events.add(new XMLEvent(time, type, course));
...
}
}
The XMLEvent class to go something like:
class XMLEvent {
@Root(name="professor")
XMLEvent(DateTime time, LogType type, Professor p){
...
}
@Root(name="student")
XMLEvent(DateTime time, LogType type, Student st){
...
}
@Root(name="course")
XMLEvent(DateTime time, LogType type, Course c){
...
}
}
For the output to be:
<events>
<professor> ... </professor>
<student> ... </student>
<course> ... </course>
</events>
So depending on the constructor I call to create a new XMLEvent the root name to which is mapped is different. Is this even possible?
Of course the past example was just to transmit what I need. Putting the @Root annotation there didn't change anything
Thanks!