Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:00:32+00:00 2026-06-05T05:00:32+00:00

I have two classes: package a; class A { private <type> fieldOfClassA; // getters,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:00:35+00:00Added an answer on June 5, 2026 at 5:00 am

    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 and B.

    forum10874711/a/binding1.xml

    <?xml version="1.0"?>
    <xml-bindings
        xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="forum10874711.a">
        <java-types>
            <java-type name="A">
                <java-attributes>
                    <xml-element java-attribute="fieldOfClassA" name="field-of-class-a"/>
                </java-attributes>
            </java-type>
        </java-types>
    </xml-bindings>
    

    forum10874711/b/binding1.xml

    <?xml version="1.0"?>
    <xml-bindings
        xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="forum10874711.b">
        <java-types>
            <java-type name="B">
                <xml-root-element/>
                <java-attributes>
                    <xml-element java-attribute="fieldOfClassB" name="field-of-class-b"/>
                </java-attributes>
            </java-type>
        </java-types>
    </xml-bindings>
    

    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.

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    Demo

    package forum10874711;
    
    import java.util.*;
    import javax.xml.bind.*;
    import org.eclipse.persistence.jaxb.JAXBContextFactory;
    
    import forum10874711.b.B;
    
    public class Demo1 {
    
        public static void main(String[] args) throws Exception {
            Map<String, Object> properties = new HashMap<String, Object>(1);
            List<String> metadata = new ArrayList<String>(2);
            metadata.add("forum10874711/a/binding1.xml");
            metadata.add("forum10874711/b/binding1.xml");
            properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, metadata);
            JAXBContext jc = JAXBContext.newInstance(new Class[] {B.class}, properties);
    
            B b = new B();
            b.setFieldOfClassA("foo");
            b.setFieldOfClassB(123);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(b, System.out);
        }
    
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8"?>
    <b>
       <field-of-class-a>foo</field-of-class-a>
       <field-of-class-b>123</field-of-class-b>
    </b>
    

    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 classB` (see http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html).

    forum10874711/a/binding2.xml

    <?xml version="1.0"?>
    <xml-bindings
        xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="forum10874711.a">
        <java-types>
            <java-type name="A" xml-transient="true"/>
        </java-types>
    </xml-bindings>
    

    forum10874711/b/binding2.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <xml-bindings
        xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="forum10874711.b">
        <java-types>
            <java-type name="B">
                <xml-root-element/>
                <java-attributes>
                    <xml-element java-attribute="fieldOfClassA" name="field-of-class-a"/>
                    <xml-element java-attribute="fieldOfClassB" name="field-of-class-b"/>
                </java-attributes>
            </java-type>
        </java-types>
    </xml-bindings>
    

    Demo

    package forum10874711;
    
    import java.util.*;
    import javax.xml.bind.*;
    import org.eclipse.persistence.jaxb.JAXBContextFactory;
    
    import forum10874711.b.B;
    
    public class Demo2 {
    
        public static void main(String[] args) throws Exception {
            Map<String, Object> properties = new HashMap<String, Object>(1);
            List<String> metadata = new ArrayList<String>(2);
            metadata.add("forum10874711/a/binding2.xml");
            metadata.add("forum10874711/b/binding2.xml");
            properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, metadata);
            JAXBContext jc = JAXBContext.newInstance(new Class[] {B.class}, properties);
    
            B b = new B();
            b.setFieldOfClassA("foo");
            b.setFieldOfClassB(123);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(b, System.out);
        }
    
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8"?>
    <b>
       <field-of-class-a>foo</field-of-class-a>
       <field-of-class-b>123</field-of-class-b>
    </b>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes. package utilities; public class PostCaller { public String getUrl() {
I have the following two classes: package { import flash.display.Sprite; import flash.events.Event; public class
Let's say I have the following two classes: package example.model; public class Model {
I have two classes public class PrepaidPackage { private String name; private String serviceClassID;
I have two classes, and want to include a static instance of one class
I'd like to be able to have two protected classes in my package. That
I have two classes in a PHP application, B extending A for example. Class
I have two classes. Class A has protected method m() , a is an
I have an entity class: Cabbage.java package womble; public class Cabbage { private int
I have two classes: a base class, Foo::Base and a derived class, Foo::Base::Sub .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.