Robin Wieruch
Robin Wieruch

Reputation: 15908

Jersey - Pojo communication works, getEtntity doesnt

I used this chapter 4.3 for communicating with pojos in my rest service. At the moment I can post and get the pojo. It works fine. But when I try to get the entity of my response I get this exception:

 27.06.2012 10:44:44 com.sun.jersey.api.client.ClientResponse getEntity
 SCHWERWIEGEND: A message body reader for Java class javax.xml.bind.JAXBElement, and  Java type class javax.xml.bind.JAXBElement, and MIME media type application/xml was not found
 27.06.2012 10:44:44 com.sun.jersey.api.client.ClientResponse getEntity
 SCHWERWIEGEND: The registered message body readers compatible with the MIME media type are:
 application/xml ->

On server side I wrap the entity like this:

  res = Response.created(UriBuilder.fromUri(uriInfo.getAbsolutePath() + "/" + object.getObjectId()).build()).entity(new JAXBElement<ObjectPOJO>(new QName("objectpojo"), ObjectPOJO.class, object)).build();

I tried it as well with just wrapping the pojo without JAXBElement.

On client side I tried different approaches:

 GenericType<JAXBElement<ObjectPOJO>> objectType = new GenericType<JAXBElement<ObjectPOJO>>() {};
 objectType = (GenericType<JAXBElement<ObjectPOJO>>) res.getEntity(JAXBElement.class).getValue();

 object = res.getEntity(ObjectPOJO.class);

and so on. Does anyone know whats the right approach? Like I said, the get and post communication works fine.

Upvotes: 0

Views: 518

Answers (1)

Martin Matula
Martin Matula

Reputation: 7989

It should be:

ObjectPOJO object = res.getEntity(new GenericType<JAXBElement<ObjectPOJO>>() {}).getValue();

Upvotes: 2

Related Questions