JAXB unmarshalling without XmlRootElement annotation?

前端 未结 3 587
借酒劲吻你
借酒劲吻你 2021-02-05 12:15

Is there any way we can un-marshall for a class without @XmlRootElement annotation? Or are we obligated to enter the annotation?

for example:

public          


        
3条回答
  •  孤独总比滥情好
    2021-02-05 13:00

    If you cannot add XmlRootElement to existing bean you can also create a holder class and mark it with annotation as XmlRootElement. Example below:-

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class CustomerHolder 
    {
        private Customer cusotmer;
    
        public Customer getCusotmer() {
            return cusotmer;
    }
    
        public void setCusotmer(Customer cusotmer) {
            this.cusotmer = cusotmer;
        }
    }
    

提交回复
热议问题