views:

119

answers:

1

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 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?

A: 

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.

Joey