Hi Robert,
Robert Feustel wrote:
> Hiho Jörg,
>
> The problem appears to be that xstream is (in contrast to the default
> serialization?) automatically trying to serialize parent classes as
> well... Even if they aren't serializable (I know that part is not a bug,
> but a feature ;))
Actually, it is ... since XStream serializes any type, not just Serializable
ones. And XStream cannot tell, whether the implementation of a Serializable
type actually handles such a case on purpose or the type was never meant to
be serialized with Java serialization and therefore does not handle the
situation.
> Can I turn that off somehow? This is what breaks my xstream, because
> there are some objects referenced there that cannot be serialized using
> a standard ObjectOutputStream. And they shouldn't be in the xml in the
> first place, because they are (although not marked) transient. I really
> don't want to have to recheck my entire hierarchy for that.
It's nothing you can configure, but you can create a customized
SerializationConverter:
================ %< ===========
class ProperSerializableConverter extends SerializableConverter {
ProperSerializableConverter(Mapper mapper, ReflectionProvider
reflectionProvider, ClassLoaderReference classLoaderReference) {
super(mapper, reflectionProvider, classLoaderReference);
}
boolean canConvert(Class type) {
return type == YourType.class;
}
protected void marshalUnserializableParent(HierarchicalStreamWriter
writer, MarshallingContext context, Object replacedSource) {
// do nothing on purpose
}
}
xstream.registerConverter(
new ProperSerializableConverter(
xstream.getMapper(),
xstream.getReflectionProvider(),
xstream.getClassLoaderReferenfce()));
================ %< ===========
> Or should I really implement a serialization method for the parent?
> Parent data is stored during serialization, but I just moved that to the
> child classes (parent is abstract and most data in it not serialized
> anyway)...
>
> Looking forward to hearing from you,
I did not test the solution above, but it should be working since the whole
unserializable-parent element is simply omitted.
Cheers,
Jörg
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email