簡體   English   中英

如何在 MOXy 中使用實例化的 XmlAdapter?

[英]How to use instantiated XmlAdapter in MOXy?

在沒有 MOXY 的情況下使用 JAXB 時,我做了如下解組。

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

但是在使用 MOXy 的 JAXBContextFactory 的時候,createContext 的時候會出錯。

因為@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

如何在 MOXy 中使用實例化的 XmlAdapter?

這對於 MOXY 是不可能的。

我使用 spring-oxm 的 Jaxb2Marshaller 而不是 MOXy 來讓它工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM