users@jersey.java.net

[Jersey] Re: UnmarshalException with Client API

From: Joseph Mocker <jmocker_at_velti.com>
Date: Thu, 7 Mar 2013 16:13:51 +0000

To your first question, the example here on slide 10 would seem to suggest you can specify the "template" in target(), not just path();

        http://www.slideshare.net/arungupta1/jax-rs20

I've not used the 2.0 API yet.

   --joe

Joseph Mocker | Velti | Senior Software Architect
t +1.650.566.7033 m +1.408.676.6625
e jmocker_at_velti.com @Mobclix

The leading global technology provider of
mobile marketing and advertising solutions

On Mar 7, 2013, at 8:02 AM, Arun Gupta wrote:

> Figured out ...
>
> I need to create the request as:
>
> client.target("http://"
> + request.getServerName()
> + ":"
> + request.getServerPort()
> + request.getContextPath()
> + "/webresources/movie")
> .path("{movie}")
> .resolveTemplate("movie", id)
> .request()
> .get(Movie.class);
>
> Two differences here ...
>
> - Seems like I cannot specify the variable part of the URI in target(...) and have to use the builder path(...) for that. Why ?
> - I had to specify the type as Movie instead of Movie[]. My mistake, but the error was quite meaningless IMHO :-)
>
> Arun
>
> On 3/7/13 3:35 PM, Arun Gupta wrote:
>> 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
>