Ich erhalte eine ClassCastException, wenn ich versuche, ein Objekt in einer XML-Notation zu entpacken.Wie kann ein InputStream mit JAXB entpackt werden?
Mein Desktopclient fordert einen RESTful-Service, der die korrekt formatierte und validierte Liste zurückgibt.
Das Verfahren, das die Ausnahme ausspuckt ist:
public class DecodeXML {
JAXBContext jaxbContext;
Unmarshaller jaxbUnmarshaller;
public Agent convertXmlToAgent(InputStreamReader inputStreamReader) {
// XStream xstream = new XStream();
// xstream.processAnnotations(Agent.class);
// xstream.processAnnotations(FtpConnection.class);
// xstream.processAnnotations(SmtpConnection.class);
// xstream.processAnnotations(SqlConnection.class);
//
// return (Agent) xstream.fromXML(inputStreamReader);
try {
jaxbContext = JAXBContext.newInstance(Agent.class);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.unmarshal(inputStreamReader);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (Agent) jaxbUnmarshaller;
}
}
Der Kommentar gesetzt Abschnitt ist die frühere Implementierung von bewege ich mich.
Die Agent
pojo ist
@XmlRootElement (name = "agent")
@XmlAccessorType(XmlAccessType.NONE)
public class Agent extends BasePojo {
private static final long serialVersionUID = 1L;
@XmlElement(name = "description")
private String description;
@XmlElement(name = "agentId")
private String agentId;
@XmlElement(name = "ftpConnection")
private FtpConnection ftpConnection;
@XmlElement(name = "smtpConnection")
private SmtpConnection smtpConnection;
@XmlElement(name = "sqlConnection")
private SqlConnection sqlConnection;
@XmlElement(name = "pollIntervall")
private Integer pollInterval;
@XmlElement(name = "lastExecutionDate")
private Date lastExecutionDate;
// getters and setters
Was soll ich hier nicht sehen?