ive got this exception.
My Object looks like this:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ObjectDTO implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8545841080597549468L;
@XmlElement(name="objectId")
private String objectId;
@XmlElement(name="owner")
private String owner;
@XmlElement(name="objectName")
private String objectName;
Constructor, getter/setter, toString, Hash...
Now I invoke my service method with:
ClientResponse postRes = service.path("rest").path("object").accept(MediaType.APPLICATION_XML).post(ClientResponse.class, object);
When I do
System.out.println(postRes.getEntity(ObjectDTO.class));
it works fine. But when I try to do a get operation on my object like:
String string = postRes.getEntity(ObjectDTO.class).getObjectId();
I get the exception.
javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException: Premature end of life.]
Whats wrong?
Looks like you are trying to read the entity twice (the second time the entity stream is already consumed). Instead of calling postRes.getEntity() twice, call it just once, store the result in a variable and then operate on that variable.