Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy support for inheritance (Java -> XML)
MOXy support for inheritance (Java -> XML) [message #658209] Mon, 07 March 2011 12:26 Go to next message
Xavier Coulon is currently offline Xavier CoulonFriend
Messages: 58
Registered: July 2009
Member
Hello,


I'm currently evaluating MOXy in the case of unmarshalling an input XML fragment file into a Java class (or set of classes).

The Java class itself inherits from generic business classes, and most of the properties/attributes belong to the superclasses. Since i cannot modify those business classes, I use the external metadata facility provided by MOXy to configure the XML->Java mappings.

Here's a sample of that metadata config file:
<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
	xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/oxm  eclipselink/xsds/eclipselink_oxm_2_2.xsd"
    package-name="xyz.integration.stocks.domain">
 
  <java-types>
    <java-type name="xyz.integration.stocks.domain.Stock"
      xml-accessor-type="PUBLIC_MEMBER" >
      <xml-root-element name="stock" />
      <xml-type name="stock" />
      <java-attributes>
        <xml-element java-attribute="ref" 
          xml-path="ref/text()" />
      </java-attributes>
    </java-type>
  </java-types>

</xml-bindings>



Starting a JUnit test case, I get the following warning message :
Ignoring attribute [ref] on class [xyz.integration.stocks.domain.IntegrationStock] as no Property was generated for it  


As expected from the message above, the mapping is skipped and my result class property 'ref' is null...
How can I tell MOXy to support such an inheritance ?

Thank you in advance.
Regards
/Xavier
Re: MOXy support for inheritance (Java -> XML) [message #658262 is a reply to message #658209] Mon, 07 March 2011 15:56 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi Xavier,

You can fix this by using the bindings file to mark the super class (GenericBusinessClass) transient:

<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/oxm  eclipselink/xsds/eclipselink_oxm_2_2.xsd"
    package-name="xyz.integration.stocks.domain">
 
  <java-types>
    <java-type name="xyz.integration.stocks.domain.GenericBusinessClass" xml-transient="true"/>
    <java-type name="xyz.integration.stocks.domain.Stock"
      xml-accessor-type="PUBLIC_MEMBER" >
      <xml-root-element name="stock" />
      <xml-type name="stock" />
      <java-attributes>
        <xml-element java-attribute="ref" 
          xml-path="ref/text()" />
      </java-attributes>
    </java-type>
  </java-types>

</xml-bindings>


-Blaise
Re: MOXy support for inheritance (Java -> XML) [message #658315 is a reply to message #658262] Mon, 07 March 2011 20:35 Go to previous messageGo to next message
Xavier Coulon is currently offline Xavier CoulonFriend
Messages: 58
Registered: July 2009
Member
Hi Blaise,

Thank you very much, it works great !

I just needed to modify your answer because the GenericBusiness class was not in the same package, so I added a second eclipse-oxm.xml file for the second package.

May I ask you: where can I find a complete documentation on the xml metadata configuration ? Those options are very powerful Wink

Thank you in advance
Regards,
/Xavier
Re: MOXy support for inheritance (Java -> XML) [message #659289 is a reply to message #658315] Fri, 11 March 2011 21:15 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi,

Intro articles can be found here:

- http://bdoughan.blogspot.com/2010/12/extending-jaxb-represen ting-annotations.html
- http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLin k-OXM.XML

We are currently updating our user guide. All this information will soon be available here:

- http://wiki.eclipse.org/EclipseLink/UserGuide/MOXy


All of the details can be found in the supporting design documents:

- http://wiki.eclipse.org/EclipseLink/DesignDocs/277920
- http://wiki.eclipse.org/EclipseLink/DesignDocs/293925
- http://wiki.eclipse.org/EclipseLink/DesignDocs/317962

-Blaise
Previous Topic:NoSuchMethod - sufix _vh
Next Topic:Maven Trouble: Can't get Nexus to proxy the eclipselink repository
Goto Forum:
  


Current Time: Tue Apr 23 17:40:21 GMT 2024

Powered by FUDForum. Page generated in 0.03738 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top