JAXB: attribute name undefined for XmlElement annotation type

When I try to assign an attribute nameto XmlElementfor JAXB, I get an error in Eclipse:

The attribute name is undefined for the annotation type XmlElement

An example of my model class:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Components {

    Component component;

    @XmlElement(name = "component")  // error on this line
    public void setComponent(Component component) {
        this.component = component;
    }
}

I am trying to use this answer .

+4
source share
1 answer

Well, it turns out it was a stupid mistake. I have imported

import com.sun.xml.internal.txw2.annotation.XmlElement;

instead

import javax.xml.bind.annotation.XmlElement;
+6
source

Source: https://habr.com/ru/post/1536514/


All Articles