I have beans which have Objects which can contain different types. Now when I create XML it will add class attribute to serialized object. I would like to change that for example class simple name.
Example Java:
public class MyParentClass {
private Object childObjectAttribute; // Can be any instance of any interface ...
// Getters & setters etc..
XStream initialization:
public XStream getXStream()
{
XStream xstream = new XStream();
Class<?>[] c = { MyInterfaceImpl.class }; // MyInterfaceImpl has of course @XStreamAlias("MyInterface")
xstream.processAnnotations(c);
xstream.alias(MyInterface.class.getSimpleName(), MyInterface.class, MyInterfaceImpl.class);
return xstream;
}
Example XML:
<myParentClass>
<childObjectAttribute class="com.example.PossibleClass"/>
</myParentClass>
I would like to change com.example.PossibleClass to PossibleClass or something else. Is that possible?
PossibleClass
without package name can cause deserialization problems when multiple packages contain a class of that name. For this, it may be impossible. – Octavla