JAXB2: Mapping nested elements into the same Java class

后端 未结 2 1258
温柔的废话
温柔的废话 2021-01-18 22:02

I\'m having trouble trying to map nested elements into the same Java class.

XML

What I\'m trying to do here is to set id attrib

2条回答
  •  耶瑟儿~
    2021-01-18 22:42

    If you use EclipseLink JAXB (MOXy) then you can leverage the @XmlPath extension for this (I'm the MOXy tech lead):

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlRootElement;
    
    import org.eclipse.persistence.oxm.annotations.XmlPath;
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class SlideText extends Slide {
    
        @XmlPath("layout/text/text()")
        private String  text;
    
    }
    
    • http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geocode-example.html

    Using standard JAXB you could leverage an XmlAdapter:

    • http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html

提交回复
热议问题