On Apr 28, 2009, at 6:43 AM, Chad McHenry wrote:
> A JAXBContextResolver I created is not being used, and my Resources
> are producing JSON output which looks like "mapped" builder rather
> than from the "natural" builder I expect. There are no errors at
> runtime.
>
> How should my JAXBContextResolver be found by Jersey?
The same why that root resource classes are found e.g. declare the
package where JAXBContextResolver resides or make it a Spring bean.
> It seems I have not configured something correctly, as it is never
> instantiated, nor is getContext() invoked.
>
> Is there something special I need to do in spring or jersey to get
> this @Provider recognized?
>
What is the package of JAXBContextResolver and what is your web.xml
configuration?
> I am using jersey-1.0.2 with spring-2.5.6 (and tried with
> jersey-1.0.3 with the same results).
>
You could register JAXBContextResolver as a singleton spring bean e.g.
annotate with spring annotation @Component
Paul.
> @Provider
> public final class JAXBContextResolver implements
> ContextResolver<JAXBContext> {
>
> private final JAXBContext context;
> private final Set<Class<?>> types;
> private final Class<?>[] cTypes = { MyClass.class }
>
> public JAXBContextResolver() throws Exception {
> // logging shows this is never executed
> this.types = new HashSet<Class<?>>(Arrays.asList(cTypes));
> this.context = new
> JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
> }
>
> public JAXBContext getContext(Class<?> objectType) {
> // logging shows this is never executed
> return (types.contains(objectType)) ? context : null;
> }
> }
>
> ...Chad