Re: [Simple-support] A question about enum support
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-01-12 09:33:43
|
Hi,
Take a look at the org.simpleframework.xml.transform.Transform interface. You need to write a Transform implementation that will be used to convert your enums.
There are many examples in the test cases.
Niall
--- On Wed, 12/1/11, David Wu <wud...@gm...> wrote:
From: David Wu <wud...@gm...>
Subject: [Simple-support] A question about enum support
To: sim...@li...
Received: Wednesday, 12 January, 2011, 1:29 AM
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
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|