users@jersey.java.net

Re: [Jersey] Re: resources inheritance

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 12 Aug 2009 08:20:56 +0200

On Aug 12, 2009, at 12:15 AM, Martin Probst wrote:

> I think the issue with generic collections is that at runtime, the
> type information is lost - that is, in Java you cannot find out if
> something is an instance of Collection<String> or Collection<Integer>.
> To fix the issue, you need to use a GenericEntity.
>

The issue is that Jersey does not resolve Collection<T> to a
"concrete" type like it resolves T.

The runtime detects whether a resource method returns a type variable
and will resolve it to a concrete type. But when something like
Collection<T> or Map<K, V> is returned the problem gets harder and i
have not solved it yet to support a general resolving mechanism for
any type variable embedded within a parameterized type. There is no
support in the JDK to resolve stuff like this but it would be
incredibly useful for frameworks that utilize reflection.

Paul.

> Also, why on earth do you use Vector? :-)
>
> Martin
>
> 2009/8/11 Felipe Gaścho <fgaucho_at_gmail.com>:
>> got it !!!
>>
>> using Arrays, everything works....... very nice.............
>>
>> 2009/8/11 Felipe Gaścho <fgaucho_at_gmail.com>:
>>> wow, it worked :)... but:
>>>
>>> for generic collections I got a problem:
>>>
>>> A message body writer for Java type, class java.util.Vector, and
>>> MIME
>>> media type, application/xml, was not found
>>>
>>> the code:
>>>
>>> public abstract class PujGenericResource<T extends
>>> AbstractArenaEntity> {
>>> @GET
>>> @Produces( { MediaType.APPLICATION_XML,
>>> MediaType.APPLICATION_JSON })
>>> @Path("/{offset}/{limit}")
>>> public Collection<T> selectAll(@PathParam("offset") int
>>> offset,
>>> @PathParam("limit") int limit) {
>>> return getFacade().readAll(offset, limit);
>>> }
>>>
>>>
>>> perhaps converting that for arrays..
>>>
>>> 2009/8/11 Felipe Gaścho <fgaucho_at_gmail.com>:
>>>> I guess I asked this before, but: may I create:
>>>>
>>>> public abstract class PujGenericResource<T extends
>>>> AbstractArenaEntity> {
>>>> protected abstract PujEntityFacade<T> getFacade();
>>>>
>>>> @PUT
>>>> @Consumes( { MediaType.APPLICATION_XML,
>>>> MediaType.APPLICATION_JSON })
>>>> @Produces( { MediaType.APPLICATION_XML,
>>>> MediaType.APPLICATION_JSON })
>>>> public T insert(T entity) {
>>>> return getFacade().create(entity);
>>>> }
>>>>
>>>> and then create a concrete subclass .. and it will work with
>>>> jersey ?
>>>>
>>>> --
>>>> Looking for a client application for this service:
>>>> http://fgaucho.dyndns.org:8080/footprint-service/wadl
>>>>
>>>
>>>
>>>
>>> --
>>> Looking for a client application for this service:
>>> http://fgaucho.dyndns.org:8080/footprint-service/wadl
>>>
>>
>>
>>
>> --
>> Looking for a client application for this service:
>> http://fgaucho.dyndns.org:8080/footprint-service/wadl
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>