I have some class with codeBased enum filed. And i have xml serealized object of this class. But when I try to deserialize this xml with XStream I receive:
com.thoughtworks.xstream.converters.ConversionException: No enum constant com.functest.util.TriState.0 : No enum constant com.functest.util.TriState.0
Class
class Params{ String clientCode; TriState triState; }
xmlParameters String
<Params> <clientCode>1516001</clientCode> <triState>0</triState> </Params>
TriState
enum TriState implements codeBased{ YES(1); NO(0); UNDEFINED(-1); int code; TriState fromCode(int code){ if(code == 1) return YES; if(code == 0) return NO; return UNDEFINED; } }
And I try to deserialize xml like this:
XStream xStream = new XStream(); xStream.alias("triState", TriState.class); Params p = xStream.fromXML(xmlParameters) as Params;
How can I set deserialization rules to get value from xml and invoke enums method fromCode(0) ?
No comments:
Post a Comment