users@jersey.java.net

[Jersey] Re: Holder Objects

From: John Yeary <johnyeary_at_gmail.com>
Date: Tue, 13 Mar 2012 09:07:39 -0400

I am not sure if I understand the question, but let me see if I can answer
it.

The API for GenericEntity<T> has an example of usage. If I had a
List<Widget> which I wanted to return (assuming POJO mapping is enabled), I
would wrap the response back to the caller (client) something like this

@GET
@Produces({MediaType.APPLICATION_JSON})
public Response getWidgets() {
List<Widget> widgets = WidgetDAO.getAllWidgets();
GenericEntity<List<Widget>> ge = new GenericEntity<List<Widget>>(widgets){};
return Response.ok(ge);
}

____________________________

John Yeary
____________________________
*NetBeans Dream Team*
*President Greenville Java Users Group
Java Users Groups Community Leader
Java Enterprise Community Leader*

____________________________

<http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary>
<http://www.youtube.com/johnyeary>
  <http://www.linkedin.com/in/jyeary>
<https://plus.google.com/112146428878473069965>
  <http://www.facebook.com/jyeary>
<http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
  <http://netbeans.org/people/84414-jyeary>

"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
-- Theodore Roosevelt



On Tue, Mar 13, 2012 at 8:55 AM, Meeraj Kunnumpurath <
mkunnumpurath_at_googlemail.com> wrote:

> Thanks John
>
> Can I use these as parameters for sending responses rather than return
> types?
>
> Sent from my iPhone
>
> On 13 Mar 2012, at 12:23, John Yeary <johnyeary_at_gmail.com> wrote:
>
> Hello Meeraj,
>
> There are a couple of value holder objects which are used in Jersey;
> GenericEntity<T> and GenericType<T>. Please see the API documents below to
> see if these meet your needs.
>
>
> http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/core/GenericEntity.html
>
> http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/GenericType.html
>
> ____________________________
>
> John Yeary
> ____________________________
> *NetBeans Dream Team*
> *President Greenville Java Users Group
> Java Users Groups Community Leader
> Java Enterprise Community Leader*
>
> ____________________________
>
> <http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary> <http://www.youtube.com/johnyeary>
> <http://www.linkedin.com/in/jyeary> <https://plus.google.com/112146428878473069965>
> <http://www.facebook.com/jyeary> <http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
> <http://netbeans.org/people/84414-jyeary>
>
> "Far better it is to dare mighty things, to win glorious triumphs, even
> though checkered by failure, than to take rank with those poor spirits who
> neither enjoy much nor suffer much, because they live in the gray twilight
> that knows not victory nor defeat."
> -- Theodore Roosevelt
>
>
>
> On Tue, Mar 13, 2012 at 7:52 AM, Meeraj Kunnumpurath <
> mkunnumpurath_at_googlemail.com> wrote:
>
>> Hi,
>>
>> Does Jersey support holder objects, which can be used as out parameters.
>> What I am trying to achieve is something along the lines ...
>>
>> public class Holder<T> {
>> private T held;
>> public T getHeld(T held) { return held; }
>> public void setHeld(T held) { this.held = held; }
>> }
>>
>> @XmlRootElement
>> public class MyRequest {
>> }
>>
>> @XmlRootElement
>> public class MyResponse {
>> }
>>
>> @Resource
>> public class MyResource {
>>
>> @POST
>> public void myMethod(MyRequest myRequest, Holder<MyResponse> holder) {
>> holder.setHeld(new MyResponse());
>> }
>>
>> }
>>
>> If there is no holder API out of the box, is there an SPI I can use to
>> plugin this behavior?
>>
>> Kind regards
>> Meeraj
>>
>>
>
>