Handling nested elements in JAXB

前端 未结 4 809
梦毁少年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:24

    Worth mentioning, if the content is a list of instead of a single instance:

    
        
            
            
            ...
        
    
    

    then you can use the @XmlElementWrapper annotation:

    @XmlRootElement(name = "root")
    public class Root {
    
        @XmlElementWrapper(name = "wrapper")
        @XmlElement(name = "entity")
        private List entity;
    
        static class Entity { }
    
    }
    

提交回复
热议问题