Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-5980

JAX-RS 2.0 client: response.readEntity(new GenericType<...>{}) fails with "unexpected element" UnmarshalException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.1
    • Fix Version/s: NeedMoreInfo
    • Component/s: JAX-RS
    • Labels:
      None
    • Environment:

      Ubuntu 14.04, Oracle Java 7

    • Estimated Complexity:
      Unknown

      Description

      The following code fails:

      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;
      }
      

      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):

      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
      

      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.

        Attachments

          Activity

            People

            • Assignee:
              sergey_beryozkin Sergey Beryozkin
              Reporter:
              karlmdavis Karl M. Davis
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: