XStream Alias Compatibility With Previous Files Content Structure

119 views Asked by At

I am facing the following issue: I've got a file automatically created with XSTream that is properly write and read.

My question is that I want to move a class (InstallationUser) from one package to another one but this is creating a parsing exception on XStream:

com.thoughtworks.xstream.converters.ConversionException: myproject.data.clientconfiguration.InstallationUser : myproject.data.clientconfiguration.InstallationUser ---- Debugging information ---- message : myproject.data.clientconfiguration.InstallationUser cause-exception
: com.thoughtworks.xstream.mapper.CannotResolveClassException cause-message : myproject.data.clientconfiguration.InstallationUser class
: java.util.TreeMap required-type : java.util.TreeMap converter-type : com.thoughtworks.xstream.converters.collections.TreeMapConverter path : /CLIENT_CONFIGURATION/network/NETWORK/users/entry/myproject.data.clientconfiguration.InstallationUser class[1] : myproject.data.clientconfiguration.InstallationDetails converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter class[2] : java.util.Vector converter-type[2] : com.thoughtworks.xstream.converters.collections.CollectionConverter class[3] : myproject.data.clientconfiguration.ClientConfiguration version
: null

After that, the data that I am loading is lost.

I am guessing that this is my fault because I don't make an Alias of this class before.

I checked and If I don't make the moving of the class from one package to the other, it works without problem.

So, what I want to know if there is some way to advise XStream parser that the previous class:

myproject.data.clientconfiguration.InstallationUser

Could be now on:

myproject.data.clientconfiguration.newpackage.InstallationUser

Thanks for your help in advance

1

There are 1 answers

1
Dalija Prasnikar On BEST ANSWER

Set alias to match your old class name, and you can move your class to any package you want.

XStream xstream = new XStream();
xstream.alias("myproject.data.clientconfiguration.InstallationUser", InstallationUser.class);