Handling nested elements in JAXB

前端 未结 4 875
梦毁少年i
梦毁少年i 2021-02-05 12:48

I am wondering if it is possible to have JAXB not to create Java object for XML elements that serve as wrappers. For example, for XML of the following structure

         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 13:27

    EclipseLink MOXy offers a JAXB 2.2 implementation with extensions. One of the extended capabilities is to use XPath to navigate through layers of the XML you don't want in you domain model.

    If you look at:

    http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/MOXyExtensions

    you will notice that the Customer's name is stored within but that the name is a String attribute of Customer. This is accomplished using:

    @XmlPath("personal-info/name/text()")
    public String getName() {
        return name;
    }
    

    I hope this helps,

    Doug

提交回复
热议问题