Consider the following enum annotated with simple-xml annotations:
@Root(name="days")
public enum DaysOfWeek {
SUNDAY("blue", 30),
MONDAY("green", 60),
TUESDAY("yellow", 50),
WEDNESDAY("red", 45),
THURSDAY("black", 45),
FRIDAY("white", 65),
SATURDAY("brown", 40);
@Attribute(name="color")
private String color;
@Element(name="mins")
private int minutes;
DaysOfWeek(String color, int minutes){
this.color = color;
this.minutes = minutes;
}
DaysOfWeek(){
/*
* Default constructor
*/
}
public void setColor(String color){
this.color = color;
}
public void setMinutes(int minutes){
this.minutes = minutes;
}
public String getColor(){
return this.color;
}
public int getMinutes(){
return this.minutes;
}
}
And, the code that uses simple framework to serialize it into XML:
StringWriter writer = new StringWriter();
try {
serializer.write(DaysOfWeek.TUESDAY, writer);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(writer.toString());
With simple-2.6, I see this output - which is what I expect:
<days color="yellow">
<mins>50</mins>
</days>
However, the same code, when serialized with simple-2.6.7, gives this:
<daysOfWeek>TUESDAY</daysOfWeek>
Basically, in simple-2.6.7, the individual members of an enum (and the simple-xml annotations on them) are ignored and always the name of the enum constant is used for serialization.
Is this intended? How do I get the latest version of simple-xml to serialize an enum while taking the individual members of the enum into consideration?