users@jersey.java.net

[Jersey] UnmarshalException with Client API

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Thu, 07 Mar 2013 15:35:17 +0000

I have a REST endpoint that can be accessed as:

http://localhost:8080/movieplex7/webresources/movie/1

with no exceptions in GlassFish 4, b78.

However when this endpoint is accessed using Client API as:

             Client client = ClientBuilder.newClient();
             Movie[] movies = client.target("http://"
                     + request.getServerName()
                     + ":"
                     + request.getServerPort()
                     + request.getContextPath()
                     + "/webresources/movie/{id}")
                     .resolveTemplate("id", id)
                     .request()
                     .get(Movie[].class);

then it throws an error:

Caused by: javax.xml.bind.UnmarshalException
  - with linked exception:
[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 63;
unexpected element (uri:"", local:"actors"). Expected elements are
<{}movie>]
     at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:435)
     at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:372)
     at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:342)
     at
org.glassfish.jersey.message.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:353)
     ... 49 more

If no template is specified then the Client API behaves as expected as well.

Any thoughts ?

Arun

-- 
http://twitter.com/arungupta
http://blogs.oracle.com/arungupta