[Simple-support] A question about enum support
Brought to you by:
niallg
|
From: David Wu <wud...@gm...> - 2011-01-12 09:29:07
|
Hi, all
I want to change my XML parsing tool from JAXB to Simple XML recently, and I
have a question about enum support.
In JAXB, there is an annotation "XMLEnumValue" to assign another value for
the enum name. For example:
public enum Coin {
@XmlEnumValue("1")
PENNY(1),
@XmlEnumValue("5")
NICKEL(5),
@XmlEnumValue("10")
DIME(10),
@XmlEnumValue("25")
QUARTER(25)
}
public class Test {
public Coin coin;
}
Test test = new Test();
test.coin = Coin.PENNY;
After serialization, the test object will be transferred to:
<test>
<coin>1</coin>
</test>
Then I want to do the same thing using Simple XML, however, Simple XML
doesn't have a similar annotation. and If I just define Coin like:
public enum Coin {
PENNY(1),
NICKEL(5),
DIME(10),
QUARTER(25)
}
Then after serialization, the test object will be:
<test>
<coin>PENNY</coin>
</test>
I want "1", not "PENNY", what shall I do?
Can simple XML do the similar thing, so I can use this feature?
I really need this feature, so I'd like to get help from all of you.
Thank you very much.
David
|