开发者

XStream serializable objects

开发者 https://www.devze.com 2022-12-30 09:33 出处:网络
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 do

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消