2
votes

I'm trying to map the following class with xml binding file (jaxb-moxy):

public class A{
   private String name;
   private B b;
   .....
}


public class B{
   private String surname;
}

In the binding file I have:

....
<java-type name="A" xml-accessor-type="NONE">
      <java-attributes>
           <xml-element java-attribute="b$surname" name="surname"/>
           <xml-element java-attribute="name" name="name"/>
      </java-attributes>
</java-type>
....

Unfortunately, the xml generated has always surname field empty (and I log this error message: Ignoring attribute [b$surname] on class [A] as no Property was generated for it).

Could you help me to undestand how to map member attributes?

Thanks in advance.

1

1 Answers

0
votes

If you are looking to get the following XML document:

<a>
    <surname>Doe</surname>
    <name>Jane</name>
</a>

For the classes you have posted in your question, then you could use the following mapping document. In this document you map the b field to the surname element, and then map the single field on the B class with @XmlValue.

<?xml version="1.0"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="forum22788599"
    xml-accessor-type="FIELD">
    <java-types>
        <java-type name="A">
            <xml-root-element/>
            <xml-type prop-order="b name"/>
            <java-attributes>
                <xml-element java-attribute="b" name="surname"/>
                <xml-element java-attribute="name"/>
            </java-attributes>
        </java-type>
        <java-type name="B">
            <java-attributes>
                <xml-value java-attribute="surname"/>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>