One thing that is really important to understand considering you have an XML file as :
<customer id="100">
<Age>29</Age>
<NAME>mkyong</NAME>
</customer>
I am sorry to inform you but :
@XmlElement
public void setAge(int age) {
this.age = age;
}
will not help you, as it tries to look for "age" instead of "Age" element name from the XML.
I encourage you to manually specify the element name matching the one in the XML file :
@XmlElement(name="Age")
public void setAge(int age) {
this.age = age;
}
And if you have for example :
@XmlRootElement
@XmlAccessorType (XmlAccessType.FIELD)
public class Customer {
...
It means it will use java beans by default, and at this time if you specify that you must not set another
@XmlElement(name="NAME")
annotation above a setter method for an element <NAME>..</NAME>
it will fail saying that there cannot be two elements on one single variables.
I hope that it helps.