On Apr 27, 2009, at 6:51 PM, Tatu Saloranta wrote:
> On Mon, Apr 27, 2009 at 4:12 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>  
> wrote:
> ...
>>> My problem seems to be the next step; ensuring that my
>>> ContextProvider<T> matches with call. Looks like MediaType doesn't
>>> match by default for some reason (if I pass type I get in).
>>
>> Can you show me the implementation code?
>
> Sure. I'll attach the full file, but here's the snippet I think is  
> relevant:
>
> ---
>    protected ObjectMapper _getMapper(Class<?> type, MediaType  
> mediaType)
>    {
>        // First: were we configured with an instance?
>        if (_configuredMapper != null) {
>            return _configuredMapper;
>        }
>
>        // If not, maybe we can get one configured via context?
>        ContextResolver<ObjectMapper> resolver =
> _providers.getContextResolver(ObjectMapper.class, mediaType);
>        // Not registered with media type, how about without?
>        if (resolver == null) {
>            resolver =  
> _providers.getContextResolver(ObjectMapper.class, null);
>        }
> ---
>
I think there is an issue further on:
         if (resolver != null) {
             ObjectMapper mapper =  
resolver.getContext(ObjectMapper.class);
You should be passing in the "type" argument rather than  
ObjectMapper.class
             if (mapper != null) {
                 return mapper;
             }
         }
> Oh, and the other part is the provider for ObjectMapper:
>
> ---
> @Provider
> /* Produces ObjectMappers for all types...
> * not sure what's the magic incantation; default should be "any types"
> */
> @Produces
> public final class ObjectMapperHolder
>    implements ContextResolver<ObjectMapper>
> {
>   //....
>    public ObjectMapper getContext(Class<?> type)
>    {
>        if (type == ObjectMapper.class) { // should always be true
>            return _mapper;
The type should never be equal to ObjectMapper.class unless you want  
to marshall/unmarshall ObjectMapper.
What trouble are you running into, are instances of  
ContextResolver<ObjectMapper> being created? is the getContext method  
being called?
Paul.
>
>        }
>        return null;
>    }
> }
> ---
>
> So it should be some mismatch between media types... but I was unable
> to declare proper type in @Produces of provider.
>
> -+ Tatu +
> < 
> JacksonJsonProvider 
> .java 
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net