I am using nice little piece of xstream to perform serialization.
I have the following class :
// version 0
class A {
}
// version 1
class A {
Object o = new Object();
}
In order for me to read version 0 xml file to construct version 1 class A, I will have to add the following method in version 1 class A :
class A {
private Object readResolve()
{
/* For backward compatible */
if (o == null) { o = new Object(); }
}
Object o = new Object();
}
This works fine so far.
Now, the situation is being reversed.
I have the following class :
// version 0
class A {
Object o = new Object();
}
// version 1
class A {
}
How can I able to make reading xml file version 0, to construct class A version 1?
Here is the exception you are going to get, if you try to do so :
run:
com.thoughtworks.xstream.converters.ConversionException: a : a
---- Debugging information ----
message : a : a
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : a : a
class : javaapplication15.Main$A
required-type : javaapplication15.Main$A
path : /javaapplication15.Main$A/a
line number : 2
-------------------------------
null
BUILD SUCCESSFUL (total time: 2 seconds)