Serializing and deserializing between different versions of the same class

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

Serializing and deserializing between different versions of the same class

morten.simonsen

Hi

First of all: XStream is great!! I have used it now for multiple purposes, without even reading one single line of doc. And it works right out of the box!! Thank you very much. :-)

First question: Let's say I have object A on server X, and object A' on server Y. The A' has either one method/parameter removed or added, but is otherwise the same object. Will serialization work
between these two objects? (If it's any help, the objects are vey simple objects, just Strings, primitives, Wrappers of primitives, array of any of these types, java.util.Calendar + other objects which may consist of any of the previous elements).

Second question: I know this is not your business, but since I have found souch a group of experts on ser/deser I thought I might give it a go: I have tested the ser/deser-mechanism in Websphere 5.1 Webservices (SOAP/HTTP). It seems to me like this algorithm is an O(n^2), where n is the number of items in a list. It doesn't look like XStream has that kind of algorithm, so why on earth would IBM do such a thing?

Morten Simonsen
--
The content of this e-mail is intended solely for the use of the individual or entity to whom it is addressed. If you have received this communication in error, be aware that forwarding it, copying it or in any way disclosing its content to  any other person, is strictly prohibited. If you have received this communication in error, please notify the author by replying to this e-mail immediately.This email has been scanned for the presence of viruses!   http://www.storebrand.no
Reply | Threaded
Open this post in threaded view
|

Re: Serializing and deserializing between different versions of the same class

Jörg Schaible-2
Hi Morten,

[hidden email] wrote:

> Hi
>
> First of all: XStream is great!! I have used it now for multiple purposes,
> without even reading one single line of doc. And it works right out of the
> box!! Thank you very much. :-)
>
> First question: Let's say I have object A on server X, and object A' on
> server Y. The A' has either one method/parameter removed or added, but is
> otherwise the same object. Will serialization work
> between these two objects? (If it's any help, the objects are vey simple
> objects, just Strings, primitives, Wrappers of primitives, array of any of
> these types, java.util.Calendar + other objects which may consist of any
> of the previous elements).

Normally you will have to use your own Converter, that is capable of
handling the missing/new elements. We have feature requests to support such
scenarios, but this is currently not handled by the default serializer:

http://jira.codehaus.org/browse/XSTR-68
http://jira.codehaus.org/browse/XSTR-210

You might have a look at the bean serializer though, but I am no familiar
with it, Mauro may comment.

> Second question: I know this is not your business, but since I have found
> souch a group of experts on ser/deser I thought I might give it a go: I
> have tested the ser/deser-mechanism in Websphere 5.1 Webservices
> (SOAP/HTTP). It seems to me like this algorithm is an O(n^2), where n is
> the number of items in a list. It doesn't look like XStream has that kind
> of algorithm, so why on earth would IBM do such a thing?

Sorry, cannot say anything useful here ...

- Jörg

Reply | Threaded
Open this post in threaded view
|

Re: Serializing and deserializing between different versions of the same class

Mauro Talevi
Jörg Schaible wrote:

> Hi Morten,
>
> [hidden email] wrote:
>
>> Hi
>>
>> First of all: XStream is great!! I have used it now for multiple purposes,
>> without even reading one single line of doc. And it works right out of the
>> box!! Thank you very much. :-)
>>
>> First question: Let's say I have object A on server X, and object A' on
>> server Y. The A' has either one method/parameter removed or added, but is
>> otherwise the same object. Will serialization work
>> between these two objects? (If it's any help, the objects are vey simple
>> objects, just Strings, primitives, Wrappers of primitives, array of any of
>> these types, java.util.Calendar + other objects which may consist of any
>> of the previous elements).
>
> Normally you will have to use your own Converter, that is capable of
> handling the missing/new elements. We have feature requests to support such
> scenarios, but this is currently not handled by the default serializer:
>
> http://jira.codehaus.org/browse/XSTR-68
> http://jira.codehaus.org/browse/XSTR-210
>
> You might have a look at the bean serializer though, but I am no familiar
> with it, Mauro may comment.
>

If A has a method and A' doesn't then the serialisation of A can't be read by A',
but if you can keep the field in A' (but declare it transient) it can be read.

If A doesn't have a method and A does then the serialisation of A can be read by A'
but the extra field will be set to null.

In general, XStream is a serialisation tool so if the object changes than you can:

- make it change keeping some form of backward compatibility
(eg keep transient private field but you can remove the public access methods for it)
- transform the serialised XML in a way that is compatible with the object changes.
- write your own converter to handle the change

As Joerg mentioned, there are change request to be able to configure ignorable fields
and we are considering them for future releases.



Reply | Threaded
Open this post in threaded view
|

Re: Serializing and deserializing between different versions of the same class

Jörg Schaible-2
Hi Mauro,

Mauro Talevi wrote:

[snip]

> If A has a method and A' doesn't then the serialisation of A can't be read
> by A', but if you can keep the field in A' (but declare it transient) it
> can be read.
>
> If A doesn't have a method and A does then the serialisation of A can be
> read by A' but the extra field will be set to null.

I assume here: s/method/member/m

> In general, XStream is a serialisation tool so if the object changes than
> you can:
>
> - make it change keeping some form of backward compatibility
> (eg keep transient private field but you can remove the public access
> methods for it) - transform the serialised XML in a way that is compatible
> with the object changes. - write your own converter to handle the change
>
> As Joerg mentioned, there are change request to be able to configure
> ignorable fields and we are considering them for future releases.

- Jörg

Reply | Threaded
Open this post in threaded view
|

Re: Serializing and deserializing between different versions of the same class

Mauro Talevi
Jörg Schaible wrote:

>> If A has a method and A' doesn't then the serialisation of A can't be read
>> by A', but if you can keep the field in A' (but declare it transient) it
>> can be read.
>>
>> If A doesn't have a method and A does then the serialisation of A can be
>> read by A' but the extra field will be set to null.
>
> I assume here: s/method/member/m

yes - member :-)