java - xStream changes order of objects in write/readObject with JSON serialization -
we use xstream serialize objects json , vice versa.
we init xstream this
xstream xstream = new xstream(new jettisonmappedxmldriver(new configuration(), false)); xstream.ignoreunknownelements(); xstream.setmode(xstream.xpath_relative_references);
we have test class
public static class testwowithbi implements serializable{ private static final long serialversionuid = -4720678317857471031l; private transient string customernickname; private transient string customeruuid; private transient biginteger discussionid; private transient string message; public testwowithbi(string customernickname, string customeruuid, biginteger discussionid, string message){ this.customernickname = customernickname; this.customeruuid = customeruuid; this.discussionid = discussionid; this.message = message; } private final void writeobject(final objectoutputstream out) throws ioexception { out.defaultwriteobject(); out.writeobject(customernickname); out.writeobject(customeruuid); out.writeobject(discussionid); out.writeobject(message); } private final void readobject(final objectinputstream in) throws ioexception, classnotfoundexception{ in.defaultreadobject(); customernickname = (string) in.readobject(); customeruuid = (string) in.readobject(); discussionid = (biginteger) in.readobject(); message = (string) in.readobject(); } }
after serialization looks this:
{ "somethere.objecttojsonserializertest$testwowithbi": { "@serialization": "custom", "somethere.objecttojsonserializertest$testwowithbi": { "default": "", "string": ["name", "uuid", "message"], "big-int": 1 } } }
and deserialization fails class cast. on 1.3.1 , 1.4.7 versions. looks bug me, may settings?
upd: seems org.codehaus.jettison.mapped.mappedxmlstreamwriter.jsonpropertyobject#withproperty
if(old != null) { jsonarray values; // convert existing property array // , append array if (old instanceof jsonarray) { values = (jsonarray)old; } else { values = new jsonarray(); values.put(old); } values.put(value); object.put(property.getkey(), values); } else if(getserializedasarrays().contains(property.getkey())) { jsonarray values = new jsonarray(); values.put(value); object.put(property.getkey(), values); } else { // add property directly. object.put(property.getkey(), value); }
it group elements of same type.
Comments
Post a Comment