java - Could not deserialize multimap with XStream / Jettison -
i'm trying serialize , deserialize guava's multimap using xstream , jettison. here's simple test illustrate:
final xstream xstream = new xstream(new jettisonmappedxmldriver()); final multimap<testenum, string> test = hashmultimap.create(); test.put(testenum.e1, "test"); final string json = xstream.toxml(test); final multimap<testenum, string> result = (multimap<testenum, string>)xstream.fromxml(json);
it gives following error:
com.thoughtworks.xstream.converters.conversionexception: not call com.google.common.collect.hashmultimap.readobject() : com.test.test$testenum cannot cast java.lang.integer ---- debugging information ---- message : not call com.google.common.collect.hashmultimap.readobject() cause-exception : java.lang.classcastexception cause-message : com.test.test$testenum cannot cast java.lang.integer class : com.google.common.collect.hashmultimap required-type : com.google.common.collect.hashmultimap converter-type : com.thoughtworks.xstream.converters.reflection.serializableconverter path : /com.google.common.collect.hashmultimap/com.google.common.collect.hashmultimap line number : -1 version : 1.4.7 -------------------------------
note error focus on multimap when used enum key. if use map instead of multimap, there's no error. if use string instead of enum key, there's no error. also, if serialize xml instead of json (that is, without "jettisonmappedxmldriver" in constructor), works perfectly.
is there solution this? i'm using workaround, replacing multimap map of collection, prefer find way keep multimap.
Comments
Post a Comment