本文介绍了你如何获得MOXy oxml映射文件来识别静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MOXy我可以在我的json输出中展平我的对象模型的部分

Using MOXy I can flatten parts of my object model in my json output

<java-type name="Medium">
  <java-attributes>
    <xml-element java-attribute="trackList" xml-path="."/>
  </java-attributes>
</java-type>

但是当我想折叠一个静态类的子类时,如下所示

but when I want to fold in a class that is a child of a static class as follows

<java-type name="Medium.TrackList">
  <java-attributes>
    <xml-element java-attribute="artistList" xml-path="."/>
  </java-attributes>
</java-type>

它抱怨

Exception Description: Could not load class [Medium.TrackList] declared in the external metadata file.  Please ensure that the class name is correct, and that the correct ClassLoader has been set.
    at org.eclipse.persistence.exceptions.JAXBException.couldNotLoadClassFromMetadata(JAXBException.java:376)
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.getXmlBindingsClasses(JAXBContext.java:979)
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:879)
    at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:157)

如何解决此问题?

推荐答案

在OXM中指定内部类时,EclipseLink实际上需要$分隔符。我重现了你的问题,并通过在你的oxm文件中修改它来修复它。

EclipseLink actually expects the "$" separator when specifying inner classes in OXM. I reproduced your issue, and fixed it by changing this in your oxm file.

<java-type name="Medium$TrackList">
  <java-attributes>
    <xml-element java-attribute="artistList" xml-path="."/>
  </java-attributes>
</java-type>

希望这会有所帮助,

Rick

这篇关于你如何获得MOXy oxml映射文件来识别静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 16:03