简体   繁体   English

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

[英]How to use instantiated XmlAdapter in MOXy?

When using JAXB without MOXY I did Unmarshal like below.在没有 MOXY 的情况下使用 JAXB 时,我做了如下解组。

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

However, when using MOXy's JAXBContextFactory, an error occurs at the time of createContext.但是在使用 MOXy 的 JAXBContextFactory 的时候,createContext 的时候会出错。

Because of @XmlJavaTypeAdapter(Something.JaxbAdapter.class).因为@XmlJavaTypeAdapter(Something.JaxbAdapter.class)。

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

Error:错误:

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

How to use instantiated XmlAdapter in MOXy?如何在 MOXy 中使用实例化的 XmlAdapter?

This was not possible with MOXY.这对于 MOXY 是不可能的。

I used spring-oxm's Jaxb2Marshaller instead of MOXy to get it working.我使用 spring-oxm 的 Jaxb2Marshaller 而不是 MOXy 来让它工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM