dev@jsr311.java.net

Re: JSR311: EntityProviders

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 05 Nov 2007 10:57:48 +0100

Stefan Tilkov wrote:
> On Nov 4, 2007, at 1:25 AM, Marc Hadley wrote:
>
>> On Nov 3, 2007, at 12:02 PM, Stefan Tilkov wrote:
>>>
>>> 1. There is no way to implement EntityProvider<T> multiple times (for
>>> different values of T) within a single class. So if I have a set of
>>> related classes I'd like to map e.g. to a single XML vocabulary, I
>>> have to create as many EntityProviders as I have classes. Right?
>>>
>> No, you can implement EntityProvider<Object> and use the
>> supports(Class<?>) method to reject types the provider doesn't support.
>>
>
> But then I'd have a single readFrom and writeTo method, typed with Object?
>

Unfortunately, because of type erasure, it is not possible to do the
following with Java generics:

   public interface IFace<T> {
     public T ambiguous(Class<T> c)
   }

   public class Impl implements IFace<Integer>, IFace<Boolean> {
     ...
   }

because the following two methods on Impl would be the same in terms of
the method parameters at runtime:

   public Integer ambiguous(Class<Integer> c)

   public Boolean ambiguous(Class<Boolean> c)

and the same applies to EntityProvider.readFrom method.


>>> 2. There is no way to have two different EntityProviders for the same
>>> class (e.g. for different MIME types), which means one has to resort
>>> to if-else-if-chains on
>>> the mediaType parameter. Correct?
>>>
>> No, you can use @ProduceMime and @ConsumeMime on the provider class to
>> declare the media types that it supports. The JSR 311 runtime will
>> only call providers that support the appropriate media type.
>>
>
> OK; this is the way I expected it to work, but couldn't get it to work
> with Jersey 0.4 (but that might be a usage error on my side).
>

It is an error on my side, sorry :-( Jersey 0.4 does not implement
Produce/Consume annotations on an EntityProvider.

I need to get my act together and implement it, of course i would be
more than happy to accept patches/contributions if people want to help
in this area :-) I will make it a priority to get this implemented for
the 0.5 release. I have created an issue to track it [1].

Paul.

[1] https://jersey.dev.java.net/issues/show_bug.cgi?id=20

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109