How should I map an abstract class with simple xml in Java?
Posted
by spderosso
on Stack Overflow
See other posts from Stack Overflow
or by spderosso
Published on 2010-06-08T17:33:40Z
Indexed on
2010/06/08
18:32 UTC
Read the original article
Hit count: 193
Hi,
I want to achieve the following xml using simple xml framework (http://simple.sourceforge.net/):
<events>
<course-added date="01/01/2010">
...
</course-added>
<course-removed date="01/02/2010">
....
</course-removed>
<student-enrolled date="01/02/2010">
...
</student-enrolled>
</events>
I have the following (but it doesn't achieve the desired xml):
@Root(name="events")
class XMLEvents {
@ElementList(inline=true)
ArrayList<XMLEvent> events = Lists.newArrayList();
...
}
abstract class XMLEvent {
@Attribute(name="date")
String dateOfEventFormatted;
...
}
And different type of XMLNodes that have different information (but are all different types of events)
@Root(name="course-added")
class XMLCourseAdded extends XMLEvent{
@Element(name="course")
XMLCourseLongFormat course;
....
}
@Root(name="course-removed")
class XMLCourseRemoved extends XMLEvent {
@Element(name="course-id")
String courseId;
...
}
How should I do the mapping or what should I change in order to be able to achieve de desired xml?
Thanks!
© Stack Overflow or respective owner