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?

有帮助吗?

解决方案

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());
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top