users@jersey.java.net

[Jersey] How to obtain the default JAXBContext?

From: Markus Karg <karg_at_quipsy.de>
Date: Mon, 9 May 2011 15:07:42 +0200

I always thought I know JAX-RS "rather well", but today I got stuck
totally with a really simple question: How to obtain the default
JAXBContext?

 

Jersey seems to find and use the default JAXBContext when calling of
this method:

 

@PUT

public void put(SomeFancyClass entity)

 

I am getting an instance of SomeFancyClass, which is a simple POJO
annotated as @XmlRootElement.

 

But if I like to get the JAXBContext that JAX-RS actually used to do the
translation, I do not get anything:

 

providers.getContextResolver(JAXBContext.class, MediaType.TEXT_XML_TYPE)

 

I am getting null for any media type (even for the wild card).

 

It is working pretty well when trying to obtain any of my custom
resolvers, but how to obtain the default resolver used by JAX-RS
internally...?

 

Thanks a lot!

Markus