How do you get MOXy oxml mapping file to recognise static classes

廉价感情. 提交于 2019-12-10 16:37:42

问题


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

i.e

<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>

it complains

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)

How do I resolve this ?


回答1:


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>

Hope this helps,

Rick



来源:https://stackoverflow.com/questions/11467530/how-do-you-get-moxy-oxml-mapping-file-to-recognise-static-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!