javajsonjaxbmoxy

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


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 ?


Solution

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