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开发者_如何学Python'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
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.
精彩评论