XMLEncoder and PersistenceDelegate

I am trying to use XMLEncoder

to write an object graph (tree in my case) to a file. However, the one class it contains is not actually a Java bean, and I don't particularly like publishing its guts. It accessed more like a list and has the corresponding add

/ methods remove

.

I've already written a custom PersistenceDelegate

one to handle this. However, it seems to me that I have to add the instance PersistenceDelegate

to the instance XMLEncoder

manually.

Is there a way to XMLEncoder

select it myself or do I really need to add it whenever I use an encoder to write a graph that the specified class can contain?

+2


a source to share


1 answer


Digging through our codebase, I came across a class XMLEncodeFactory

that allows registration PersistenceDelegates

for specific classes and handles instantiation XMLEncoder

with pre-set delegates. The code itself is very simple, but I would have thought that such a possibility would already be offered by Java.



I was told this was created after talking to the original developers of the class XMLEncoder

and there seems to be no better alternative.

+1


a source







All Articles