开发者

XMLEncoder and PersistenceDelegate

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜