users@jersey.java.net

Re: [Jersey] Resource Subclass

From: testn <test1_at_doramail.com>
Date: Fri, 26 Jun 2009 03:39:34 -0700 (PDT)

This is the ugly workaround but works quite well

public class AbstractResource<T> extends JpaDaoSupport {
        private final Class<T> clazz;
        private T[] arrClass;

        protected AbstractResource(Class<T> clazz) {
                this.clazz = clazz;
                arrClass = (T[]) Array.newInstance(clazz, 0);
        }

        @GET
        @Produces( { "application/xml", "application/json" })
        public T[] getAll() {
                List<T> list = this.getJpaTemplate().find("from " + clazz.getName());
                return list.toArray(arrClass);
        }
}



Paul Sandoz wrote:
>
>
> On Jun 26, 2009, at 10:00 AM, testn wrote:
>
>>
>> after digging more,
>>
>> @GET
>> @Produces({"application/xml", "application/json"})
>> public T getAll() {
>> return (T) this.getJpaTemplate().find("from
>> "+clazz.getName()).get(0);
>> }
>> works in the base class... but not this...
>>
>
> Yes, i forgot about that, Jersey does resolve T, the type variable to
> a Class or a concrete ParameterizedType in this case. For the case of
> List<T> etc it is more difficult to support this in a general manner,
> but i suppose it could be done, just a bit of a head scratcher...
>
> Paul.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>
%-|%-|%-|P-(
-- 
View this message in context: http://n2.nabble.com/Resource-Subclass-tp3160169p3160796.html
Sent from the Jersey mailing list archive at Nabble.com.