I have two classes:
package a;
class A {
private <type> fieldOfClassA;
// getters, and setters
}
package b;
class B extends A{
private <type> fieldOfClassB;
// getters, and setters
}
I want to marshal class B to an xml element and add the attribute fieldOfClassB, and fieldOfClassA from class A but it prints the following warning message during marshalling:
Ignoring attribute [fieldOfClassA] on class [b.B] as no Property was generated for it.
Note that the two class is from two different packages and I can't change this object model.
Thank you in advance!
EDIT:
I am using external binding files.
From the log message you posted, I can see that you are using MOXy's external mapping document (see http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html). There are a couple of different ways to map the inherited property.
OPTION #1 - Map the Inherited Property Belonging to the Parent
By default a field/property needs to be mapped within the class it belongs to. Since MOXy scopes the external mapping document at the package level, you will need separate mapping documents for
A
andB
.forum10874711/a/binding1.xml
forum10874711/b/binding1.xml
forum10874711/b/jaxb.properties
To specify MOXy as your JAXB implementation you need to add a file called
jaxb.properties
in the same package as your domain model with the following entry.Demo
Output
OPTION #2 - Map the Inherited Property Belonging to Child
The parent class
A' can be marked
@XmlTransientthis will allow us to map the inherited fields/properties on the child class
B` (see http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html).forum10874711/a/binding2.xml
forum10874711/b/binding2.xml
Demo
Output