We are building a restful api, using 2.3.5 (although I don't think the release 
level matters) and I am a bit confused on response handling within RestEasy:

Right or wrong, we made most of our resource methods return Response, using the 
GenericEntity when we wanted to return a collection of objects.    Testing up 
to now was in Chrome Advanced Rest Client.  We have our beans JAXB annotated 
and the resource 'produces' both application/xml and application/json.  For 

       @Produces({"application/json", "application/xml"})
       public Response find(@Context UriInfo uriInfo)
              List<Customer> custList = null;
              try {
                     custList = listAllPaginated();
              } catch (FinderException e) {
                     Log.getInstance().error("FinderException caught :", e );
                     throwException(Response.Status.NOT_FOUND, "Error searching 

              GenericEntity<List<Customer>> entity = new 
GenericEntity<List<Customer>>(custList) {};
              return Response.ok(entity).build();

Now, as part of writing JUnit test cases, I wanted to take the response I get 
back and put it back to object form so that I can then do a set of asserts 
against the object or list of objects returned.   I downloaded Jackson version 
1.9.11 and tried to serialize/marshal the json back to object form but keep 
getting the following error:

Exception in thread "main" 
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field 
"Customer" (Class com.jda.portfolio.api.rest.base.Customer), not marked as 
at [Source: C:\PPOSDevelopment\Trunk\API\REST\Server\response.json; line: 1, 
column: 15] (through reference chain: 

Is there a difference between Jackson json and what RestEasy produces, from I 
think Jettison?   I also took the example from User doc section 19.6.1 JSON and 
JAXB collections/arrays

[{"foo":{"@test":"bill"}},{"foo":{"@test":"monica}"}}] and tried to marshal 
that back to object form - getting the same error.

It seems like from Jackson, I would get something like:

[{"@test":"bill"},{"@test":"monica}"}] for a List<Foo> - the difference being 
the {foo: } which looks like a wrapper for the object.

I changed the code to return List<Customer> instead of the Response with 
GenericEntity including the List<Customer> but the json looks the same.

What am I doing wrong?

Are we using the Response object incorrectly?  What's really the difference 
between returning List<Customer> vs Response with the List<Customer> in the 
generic entity?

I hope this is clear, but I can provide more details if needed.

Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
Resteasy-users mailing list

Reply via email to