Search code examples
javajaxbxjc

How to make JAXB Classes with parent child relationship


I have problem to make JAXB classes for parent-child relationship with JAXB / XJC parent-child-parent navigation

I think implementation to void afterUnmarshal(Unmarshaller, Object parent). It should be create super class for all jaxb classes.

So, I binding superclass using xjc reffered JAXB Marshalling - extending an existing class

But while unmarshall xml file. occurred some exception '@XmlValue is not allow on a class that derives another class.'

Some solutions @XmlAccessorType(XmlAccessType.NONE) And @XmlTransient not works for me.

What should i do?

May i use MOXy? If this situation works good for use MOXy. Have any guide document to use it in SpringBoot?

This is my super class

public class SuperClass {
    private Object parent;
    
    public void setParent(Object parent) {this.parent = parent}
    
    public Object getParent() {return this.parent}
}

Solution

  • I guess you could use this XJC Parent Pointer Plugin which will be available in jaxb-tools 4.0.1.

    Adding this plugin will need a runtime dependency.

    If not targeting jakarta based JAXB classes, you can use the following maven coordinates org.andromda.thirdparty.jaxb2_commons:parent-pointer-plugin:1.0 from where the plugin came from. It will be backported in jaxb-tools v2 too but I can't tell the release date of 4.0.1 or 2.0.10.