Re: [Simple-support] Simple 2.6.7 doesn't handle enums in the same way as Simple 2.6 does?
Brought to you by:
niallg
|
From: Niall G. - Y. <Nia...@yi...> - 2012-11-26 22:17:31
|
Interesting, I will take a look at this. I have never annotated an enum in this way, however I do not see a problem with processing enums in this manner if there is an @Root annotation on it. I am sure this is just a minor change, ill be releasing a new version soon, if its reasonable to do so Ill add back support for serializing enums in this way.
From: Kiran Rao [mailto:tec...@gm...]
Sent: Monday, 26 November 2012 9:38 PM
To: sim...@li...
Subject: [Simple-support] Simple 2.6.7 doesn't handle enums in the same way as Simple 2.6 does?
Consider the following enun:
@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 to serialize it:
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?
--
Regards,
=======
Kiran Rao
http://curioustechizen.blogspot.com/
http://stackoverflow.com/users/570930/curioustechizen
|