I have the following class that I am going to use for unmarshalling appropriate XML document:
@XmlRootElement(name = "address")
public class AddressObject {
@XmlElement(name = "domain")
public String domain = new String();
@XmlElement(name = "ip-address")
public String ipAddress = new String();
@XmlElement(name = "user-agent")
public String userAgent = new String();
}
In order to unmarshall document, I use javax.xml.bind.Unmarshaller
. Using code below:
JAXBContext context = JAXBContext.newInstance(AddressObject.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
StreamSource streamSource = new StreamSource(new StringReader(SOME_CORRECT_XML_DOC));
JAXBElement<AddressObject> obj = unmarshaller.unmarshal(streamSource, AddressObject.class);
It works fine as long as incorrect xml uses, like below:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><hello-world></hello-world>
In the last case xml unmarshall without any errors.
Can someone explain why it's happening? I have expected to recieve any errors regarding invalid tags or something like this.