Question

Image you've got auto generated beans and you want to extend them with some extra functionality. So you extend the auto generated beans and in the same file you also extend the ObjectFactory and annotate it with @XmlRegistry.

When unmarshalling some object the extended ObjectFactory ins't used and therefore the auto generated beans are created.

What step am I missing to get my custom beans created? Can I tell JAXB which Factory to use? Or does JAXB not use the factory at all?

Was it helpful?

Solution

Yes, you need to specify the ObjectFactory when configuring your Unmarshaller. I think you can use something like this to provide your own ObjectFactory implemenation:

unmarshaller.setProperty("com.sun.xml.bind.ObjectFactory",new MyObjectFactory());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top