XML-AntwortXML Java unmarshalling Objekte
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <Film>
<film_id>1</film_id>
<title>ACADEMY DINOSAUR</title>
<description>xxx</description>
<length>86</length>
<image_id>1</image_id>
- <image>
<image_id>1</image_id>
<name>1.jpg</name>
<size>408307</size>
<type>.jpg</type>
<content>base64 byte</content>
</image>
</Film>
Ich habe erstellt pojo Klassen für Film und Bild.
Film.java
public class Film {
private String film_id;
private String title;
private String description;
private String length;
private String image_id;
private Image image;
//setter and getter methods
}
Image.java
public class Image {
private int image_id;
private String name;
private int size;
private String type;
private byte[] content;
//setter and getter methods
}
Bitte helfen Ich bin neu in diesem und ich sollte JAXB verwenden.
LÖSUNG:
I hinzugefügt
@XmlRootElement(name = "film")
public class Film {
private int film_id;
private String title;
private String description;
private int length;
private int image_id;
private Image image;
}
auf dem Getter Verfahren der Bild, ich habe @XMLElement (name = "image") gegeben.
Auf Bildklasse habe ich eine Anmerkung @XmlRootElement (name = "Bild") hinzugefügt, die mir gibt, was ich wollte.
unerwartetes Element (uri: "", local: "Film"). Erwartete Elemente sind (keine) ..... das ist der Fehler, den ich erhalte, wenn ich einen Versuch mache. public void unmarshaling (String-Ausgabe) throws JAXBException { \t \t InputStream ist = new StringBufferInputStream (output); \t \t JAXBKontext jc = JAXBContext.newInstance (Film.class); \t \t Unmarshaller u = jc.createUnmarshaller(); \t \t Film film = (Film) u.unmarshal (is); – Koushik
Warum redest du deine Frage nicht, anstatt hart zu schreiben, um Kommentare zu lesen? –