[ 
https://issues.apache.org/jira/browse/CXF-5980?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14679142#comment-14679142
 ] 

Karl M. Davis commented on CXF-5980:
------------------------------------

My code above had a very simple mistake that was preventing it from working. 
Thanks *very* much for your testcase, which helped me figure that out-- never 
would have caught it, otherwise.

The problem is the parameter that I was passing in to the {{GenericType}} 
constructor. Just removing that constructor argument fixed things.

This was broken:
{code}
        List<GameSession> games = response.readEntity(
                        new GenericType<List<GameSession>>(GameSession.class) 
{});
{code}

And this works:
{code}
        List<GameSession> games = response.readEntity(
                        new GenericType<List<GameSession>>() {});
{code}

(My apologies for the long delay in my response-- I only made it back to the 
TODO in my code that I'd left for this last night.)

> JAX-RS 2.0 client: response.readEntity(new GenericType<...>{}) fails with 
> "unexpected element" UnmarshalException
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-5980
>                 URL: https://issues.apache.org/jira/browse/CXF-5980
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.1
>         Environment: Ubuntu 14.04, Oracle Java 7
>            Reporter: Karl M. Davis
>            Assignee: Sergey Beryozkin
>             Fix For: NeedMoreInfo
>
>         Attachments: cxf-generictype-jaxrs-client-log.txt
>
>
> The following code fails:
> {code:Java}
> public List<GameSession> getGamesForPlayer() {
>       Client client = ClientBuilder.newClient();
>       Builder requestBuilder = client.target(config.getServiceRoot())
>                       .path(IGameSessionResource.SERVICE_PATH)
>                               
> .path(IGameSessionResource.SERVICE_PATH_GAMES_FOR_PLAYER)
>                       .request(MediaType.TEXT_XML_TYPE);
>       cookieStore.applyCookies(requestBuilder);
>       Response response = requestBuilder.get();
>       if (Status.Family.familyOf(response.getStatus()) != 
> Status.Family.SUCCESSFUL)
>               throw new HttpClientException(response.getStatusInfo());
>       List<GameSession> games = response.readEntity(
>                       new GenericType<List<GameSession>>(GameSession.class) 
> {});
>       cookieStore.remember(response.getCookies());
>       return games;
> }
> {code}
> With the following root exception (I'll attach the full log out/stack tracce 
> so you can see where in CXF this is coming from):
> {code}
> javax.xml.bind.UnmarshalException: unexpected element 
> (uri:"http://justdavis.com/karl/rpstourney/api/schema/v1";, 
> local:"gameSessions"). Expected elements are 
> <{http://justdavis.com/karl/rpstourney/api/schema/v1}account>,<{http://justdavis.com/karl/rpstourney/api/schema/v1}gameRound>,<{http://justdavis.com/karl/rpstourney/api/schema/v1}gameSession>,<{http://justdavis.com/karl/rpstourney/api/schema/v1}player>
>       ... 93 common frames omitted
> {code}
> This is the first time I've tried to pull a generic/collection object out of 
> a Response using CXF's JAX-RS 2.0 client, so my guess is that this is just an 
> unsupported edge case? For what it's worth, the server-side of the web 
> service being queried is hosted by the same version of CSF and handles this 
> just fine-- only the client seems to have issues.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to