简体   繁体   English

XMLEncoder / Decoder的序列化代理

[英]Serialization Proxy with XMLEncoder/Decoder

How can I implement a Serialization Proxy that can be used with a XMLEncoder/Decoder? 如何实现可与XMLEncoder / Decoder一起使用的序列化代理? The classic one (the Bloch one, I mean) doesn't work... 经典的(我是说Bloch的)是行不通的...

I believe you need to set PersistenceDelegate s for each Encoder instance. 我相信您需要为每个Encoder实例设置PersistenceDelegate You can make some changes to properties using the usual bean mechanism of providing a BeanInfo . 您可以使用提供BeanInfo的常规bean机制对属性进行一些更改。

If you look at the source you will see that there is a load of hardwired fudges for AWT and Swing beans. 如果您查看源代码,将会发现AWT和Swing bean有大量的硬糖软糖。 It really isn't nice - I suggest looking at something like JAXB. 确实不是很好-我建议您看一下JAXB之类的东西。

The short answer is that you need to write a front-end that manages serialization. 简短的答案是,您需要编写一个管理序列化的前端。 However, that will be painful, and may not give you what you want. 但是,这将很痛苦,并且可能无法满足您的需求。 The original Java serialization mechanism allowed objects to control their own serialization and deserialization, the XML implementation doesn't. 原始的Java序列化机制允许对象控制自己的序列化和反序列化,而XML实现则不能。 As far as I can tell, XMLEncoder/XMLDecoder were meant for value objects alone. 据我所知,XMLEncoder / XMLDecoder仅用于值对象。

If you describe what you're actually trying to accomplish, it's likely that someone can give you an alternative approach. 如果您描述了您实际要完成的工作,那么很可能有人可以为您提供替代方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM