Jeff Storey
Jeff Storey

Reputation: 57192

XStream serializable objects

I am currently using XStream to serialize some of my objects that don't implement Serializable. Is there a way to tell XStream to use Java's default serialization if the object does implement Serializable and to fall back on XML serialization if it does not? Or would I need to implement a simple layer on top of it to check?

thanks, Jeff

Upvotes: 0

Views: 1281

Answers (1)

skaffman
skaffman

Reputation: 403481

This would not be a good idea. Java serialization is a binary representation, XML is a textual representation.

Take java.lang.String, for instance. This implements Serializable, but clearly you would not want your Strings serialized as binary blobs inside your XML. Similarly for things like numeric types, etc.

XStream has a mechanism for registering custom converters, I suggest you use that. if you choose to serialize binary data into your XML document, you'll need to encode it somehow, e.g. with Base64 encoding.

Upvotes: 1

Related Questions