开发者

XMLEncoder and PersistenceDelegate

开发者 https://www.devze.com 2022-12-30 02:12 出处:网络
I\'m trying to use XMLEncoder to write an object graph (tree in my case) to a file. However, one class contained in it is not actually a Java bean and I don\'t particularly like making its guts public

I'm trying to use XMLEncoder to write an object graph (tree in my case) to a file. However, one class contained in it is not actually a Java bean and I don't particularly like making its guts publicly accessible. It's accessed more like a list and has appropriate add/remove methods.

I've already written a开发者_Go百科 custom PersistenceDelegate to deal with that. However, it seems that I have to add the PersistenceDelegate to the XMLEncoder instance manually.

Is there any way for XMLEncoder to pick it up on its own or do I really need to add it whenever I use an encoder to write a graph that may contain said class?


Digging through our codebase I came across a XMLEncodeFactory class which allows one to register PersistenceDelegates for certain classes and handles creating XMLEncoder instances with those delegates pre-set. The code itself is very straightforward but I would have thought such a capability would be already offered by Java.

I was told this was created after conversation with the original developers of the XMLEncoder class and there apparently isn't a nicer alternative.

0

精彩评论

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

关注公众号