|
From: Bill B. <bb...@re...> - 2013-09-04 20:06:33
|
What is your server? Tomcat? Jetty? JBoss version?
On 9/4/2013 4:02 PM, Mike Miller wrote:
> Okay, thanks - so how do I do that? I see Chapter 21 (2.3.5) talks about Maven but we aren't using maven. Do I just need to include the jar or is there something in the web.xml that I need to add to include this 'provider?
>
> Also could someone please address my last question:
>
> "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?"
>
> -----Original Message-----
> From: Bill Burke [mailto:bb...@re...]
> Sent: Wednesday, September 04, 2013 2:54 PM
> To: res...@li...
> Subject: Re: [Resteasy-users] Confused on handling response containing collections in json
>
> Switch to Jackson on the server side. We will be deprecating Jettison in the near future as it is buggy and not being well maintained.
> Jackson has all of what Jettison has and more...
>
> But you are right, Jettison produces different JSON.
>
> On 9/4/2013 3:27 PM, Mike Miller wrote:
>> 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 example:
>>
>> @GET
>>
>> @Produces({"application/json", "application/xml"})
>>
>> *public*Response find(@ContextUriInfo uriInfo)
>>
>> {
>>
>> setupQueryParms(uriInfo.getQueryParameters());
>>
>> List<Customer> custList = *null*;
>>
>> *try*{
>>
>> custList = listAllPaginated();
>>
>> } *catch*(FinderException e) {
>>
>> Log./getInstance/().error("FinderException
>> caught :", e );
>>
>> throwException(Response.Status./NOT_FOUND/,
>> "Error searching customers");
>>
>> }
>>
>> 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 ignorable
>>
>> at [Source: C:\PPOSDevelopment\Trunk\API\REST\Server\response.json;
>> line: 1, column: 15] (through reference chain:
>> com.jda.portfolio.api.rest.base.Customer["Customer"])
>>
>> 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!
>> http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.c
>> lktrk
>>
>>
>>
>> _______________________________________________
>> Resteasy-users mailing list
>> Res...@li...
>> https://lists.sourceforge.net/lists/listinfo/resteasy-users
>>
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com
>
> ------------------------------------------------------------------------------
> 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!
> http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
> _______________________________________________
> Resteasy-users mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-users
>
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|