如何使用实例化XmlAdapter在MOXy?



当使用没有MOXY的JAXB时,我做了如下的Unmarshal操作。

Unmarshaller u = this.jaxbContext.createUnmarshaller();
u.setAdapter(new Something.JaxbAdapter(this, ...));

但是,当使用MOXy的JAXBContextFactory时,在创建econtext时发生错误。

因为@XmlJavaTypeAdapter(Something.JaxbAdapter.class).

this.jaxbContext = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(classes.toArray(new Class[0]), Collections.emptyMap());

错误:

Exception [EclipseLink-50063] (Eclipse Persistence Services - 3.0.2.v202107160933): org.eclipse.persistence.exceptions.JAXBException
Exception Description: An exception occurred while attempting to instantiate XmlAdapterClass [....Somegh$JaxbAdapter]. A possible cause is that the adapter class has no zero argument constructor.
Internal Exception: java.lang.InstantiationException: ....Somegh$JaxbAdapter

如何使用实例化XmlAdapter在MOXy?

这在MOXY中是不可能的。

我使用spring-oxm的Jaxb2Marshaller而不是MOXy来使其工作。

最新更新