'javax.xml.bind.UnmarshalException converting xml to java object
My application's config file that I load, myconfig.app:
<?xml version="1.0" encoding="UTF-8"?>
<application
xmlns="http://www.example.com/com/code/app"
authentication="form">
<dummies>
<dummy id="dummy1"/>
</dummies>
</application>
Application.java
package com.code.custom;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = Application.XML_ELEMENT)
public class Application implements Serializable {
public static final String XML_ELEMENT = "application";
@XmlAttribute(name = "authentication")
protected Boolean authentication;
public Application() {}
public Boolean getAuthentication() {
return authentication;
}
}
Loading of file content:
InputStream inputStream = ..
JAXBContext context = JAXBContext.newInstance(Application.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Application obj = (Application) unmarshaller.unmarshal(inputStream);
Error:
unexpected element (uri:"http://www.example.com/com/code/app", local:"application"). Expected elements are <{}application>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
