0
我有一些類與codeBased enum
提交。我有這個類的xml serealized對象。但是,當我嘗試反序列化這個XML與XStream
我收到:Java設置XStream反序列化規則
com.thoughtworks.xstream.converters.ConversionException:沒有枚舉常量com.functest.util.TriState.0:沒有枚舉常量com.functest.util .TriState.0
類
class Params{
String clientCode;
TriState triState;
}
xmlParameters字符串
<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;
}
}
我嘗試反序列化XML這樣的:
XStream xStream = new XStream();
xStream.alias("triState", TriState.class);
Params p = (Params) xStream.fromXML(xmlParameters);
如何設置反序列化規則,從XML中獲取價值和調用枚舉法fromCode(0)
?