I have a little problem with JAXB, but unfortunately I could not find the answer.
I have a Customer class, with two name and city fields, the mapping is done using annotations, and both fields are marked as required, not nillable.
@XmlRootElement(name = "customer") public class Customer { enum City { PARIS, LONDON, WARSAW } @XmlElement(name = "name", required = true, nillable = false) public String name; @XmlElement(name = "city", required = true, nillable = false) public City city; @Override public String toString(){ return String.format("Name %s, city %s", name, city); } }
However, when I submit this XML file:
<customer> <city>UNKNOWN</city> </customer>
I will get a Customer instance with both fields set to null.
There should be no exception to check, or am I missing something in the display?
To unleash, I use:
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Customer customer = (Customer) unmarshaller.unmarshal(in);
source share