How to annotate a list using @XmlElement?

前端 未结 3 1427
忘掉有多难
忘掉有多难 2020-12-29 03:08

I have the following annotation using javax.xml.bind.annotation.XmlElement:

@XmlElement         
public List getKeywords() {
    r         


        
3条回答
  •  一整个雨季
    2020-12-29 03:55

    Use this form:

    @XmlElementWrapper(name="keywords")
    @XmlElement(name="keyword")
    

    Please note that if keywords is empty then you will get .

    Sometimes you will need to add @XmlRootElement to your class (depends on the context) and the @XmlAccessorType(XmlAccessType.?) annotation. I usually use @XmlAccessorType(XmlAccessType.FIELD) and annotate my fields with @XmlElement.

提交回复
热议问题