Search code examples
javaxml-serializationxstream

XStream - use previous serialized object after adding a function to the interface?


I use XStream to serialize an object "A" implementing an interface :

interface MyInterface { 
       String functionA();
}

MyInterface a = new MyInterface() {...}

Now the interface changed , and I added another function:

interface MyInterface {
       String functionA();
       String functionB();
}

Trying to deserialize it now fails (with the listed exception), because the interface changed - But can I make it work somehow?

This is the exception:

com.thoughtworks.xstream.mapper.CannotResolveClassException: com.cf.TestSaveSerialization$1 : com.cf.TestSaveSerialization$1
    at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:68)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
    at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:71)

I've looked at the XStream FAQ , but there's nothing about changing functions. Any idea?


Solution

  • It sounds more like there's an issue with the anonymous class, rather than XStream or the serialization mechanism itself. Are these the actual signatures? Have you tried altering the signature of a named class (a non-anonymous class)?