Ich baue eine grundlegende WebServices mit JAX-RSJAX-RS kann nicht XML-Antworttyp von GET-Methode
hier sind die GET-Methoden erhalten:
/**
* Returns all songs
* @return all songs
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Collection<Song> getAllSongs() {
return SongsRXStore.getInstance().getAllSongs();
}
/**
* Returns song with id: "id"
* @param id the "id"
* @return song with id: "id"
*/
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getSong(@PathParam("id") Integer id) {
Song song = SongsRXStore.getInstance().getSongById(id);
if (song != null)
return Response.ok(song).build();
else
return Response.status(Response.Status.NOT_FOUND)
.entity(Response.Status.NOT_FOUND + ": No Song found with id " + id).build();
}
Es scheint ganz gut, wie es ist, aber ich kann den XML-Typ nicht zurückbekommen.
Hier werden alle Songs (erste Methode oben) als json und xml angefordert. Wie Sie sehen können, wird nur der JSON korrekt zurückgegeben, aber nicht das XML.
gleiche mit nur einem bestimmten Song (zweite Methode Formular oben) anfordert:
Wie kann ich es funktioniert bitte?
EDIT: @XmlRootElemnt Tag ist natürlich allready hinzugefügt mein POJO_Bean Song.java:
@XmlRootElement(name = "song")
public class Song {
Bitte Code als Text und ** nicht als ** Bild einfügen. Danke. – zx485
ok fertig, hast du irgendeine Lösung für mein Problem? –