xStream changes order of objects in write/readObject with JSON serialization

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

xStream changes order of objects in write/readObject with JSON serialization

Анатолий Инсапов
Hello.

My problem and reseach described there http://stackoverflow.com/questions/24449238/xstream-changes-order-of-objects-in-write-readobject-with-json-serialization I suppose it is easer to read formatted text with syntax highlighting but I can copy content into mail if needed. I attach link to simplest patch in comments - http://pastebin.com/n3qpRGHS .

We use xStream 1.4.7. Is there way to fix it in 1.4.7(or 1.4.8)?

Thanks,
Anatoly
Reply | Threaded
Open this post in threaded view
|

Re: xStream changes order of objects in write/readObject with JSON serialization

Jörg Schaible-2
Hi Anatoly,

Анатолий Инсапов wrote:

> Hello.
>
> My problem and reseach described there
> http://stackoverflow.com/questions/24449238/xstream-changes-order-of-objects-in-write-readobject-with-json-serialization

This is a behavior of Jettison's heuristics transforming XML into JSON. It
will collect values from sibling elements with same name and form an array.
Which version of Jettison are you using? Note, that only Jettison 1.2 pass
XStream's unit tests, the complete 1.3.x series is borked.

> I suppose it is easer to read formatted text with syntax highlighting but
> I can copy content into mail if needed. I attach link to simplest patch in
> comments - http://pastebin.com/n3qpRGHS .
>
> We use xStream 1.4.7. Is there way to fix it in 1.4.7(or 1.4.8)?

Sorry, but there's not much we can do about it, the JSON heuristics has its
limits. See, you will get the same problem with this list:

List<Object> list = new ArrayList<>();
list.add("First");
list.add(Integer.valueOf(2));
list.add("3rd");
list.add(Long.valueOf(4));

Therefore any element sequence with arbitrary types is affected. This
includes stuff explicitly written in writeObject() as well as Exernalizable
instances, and so on...

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: xStream changes order of objects in write/readObject with JSON serialization

Анатолий Инсапов
Hello, Jörg

Thank You.
I understand limitation of JSON itself.But while list often contains objects of same type and order is not always issue, order of read/writeObject is important.
I tried jettison 1.2 and 1.0.1 but result was the same. For now we just removed our code which cause us problem during deserialization. If some legacy code will appear suppose we just use hotfix.
 
Thanks,
Anatoly


2014-07-04 1:30 GMT+04:00 Jörg Schaible <[hidden email]>:
Hi Anatoly,

Анатолий Инсапов wrote:

> Hello.
>
> My problem and reseach described there
> http://stackoverflow.com/questions/24449238/xstream-changes-order-of-objects-in-write-readobject-with-json-serialization

This is a behavior of Jettison's heuristics transforming XML into JSON. It
will collect values from sibling elements with same name and form an array.
Which version of Jettison are you using? Note, that only Jettison 1.2 pass
XStream's unit tests, the complete 1.3.x series is borked.

> I suppose it is easer to read formatted text with syntax highlighting but
> I can copy content into mail if needed. I attach link to simplest patch in
> comments - http://pastebin.com/n3qpRGHS .
>
> We use xStream 1.4.7. Is there way to fix it in 1.4.7(or 1.4.8)?

Sorry, but there's not much we can do about it, the JSON heuristics has its
limits. See, you will get the same problem with this list:

List<Object> list = new ArrayList<>();
list.add("First");
list.add(Integer.valueOf(2));
list.add("3rd");
list.add(Long.valueOf(4));

Therefore any element sequence with arbitrary types is affected. This
includes stuff explicitly written in writeObject() as well as Exernalizable
instances, and so on...

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Re: xStream changes order of objects in write/readObject with JSON serialization

Jörg Schaible-4
Hi Anatoly,

Анатолий Инсапов wrote:

> Hello, Jörg
>
> Thank You.
> I understand limitation of JSON itself.But while list often contains
> objects of same type and order is not always issue, order of
> read/writeObject is important.
> I tried jettison 1.2 and 1.0.1 but result was the same. For now we just
> removed our code which cause us problem during deserialization. If some
> legacy code will appear suppose we just use hotfix.

what you always may try is to use a different converter e.g. sometimes it is
possible to use the ReflectionConverter or a JavaBeanConverter instead. It
depends on the serialized object.

However, if I understand correctly, you already deal with JSON that has been
serialized by a former version. The proposed solution only helps if you
supervise serialization already.

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Re: xStream changes order of objects in write/readObject with JSON serialization

Анатолий Инсапов
Hello, Jörg

We serialize/deserialize our objects not external/legacy JSON. Problem arises when someone overrides write/readObject like in test case(this is compatible with java serialization). xStream pass to jettison values as is and jettison organize them into arrays but no one preserve order of operations so simplest write/readObject can be broken.

Thanks,
Anatoly


2014-07-04 15:49 GMT+04:00 Jörg Schaible <[hidden email]>:
Hi Anatoly,

Анатолий Инсапов wrote:

> Hello, Jörg
>
> Thank You.
> I understand limitation of JSON itself.But while list often contains
> objects of same type and order is not always issue, order of
> read/writeObject is important.
> I tried jettison 1.2 and 1.0.1 but result was the same. For now we just
> removed our code which cause us problem during deserialization. If some
> legacy code will appear suppose we just use hotfix.

what you always may try is to use a different converter e.g. sometimes it is
possible to use the ReflectionConverter or a JavaBeanConverter instead. It
depends on the serialized object.

However, if I understand correctly, you already deal with JSON that has been
serialized by a former version. The proposed solution only helps if you
supervise serialization already.

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email