Version 3

    Pluggable JAXBContexts With ContextResolvers

     

    You should not use this feature unless you know what you're doing.

     

    Based on the class you are marshalling/unmarshalling, RESTEasy will, by default create and cache JAXBContext instances per class type.  If you do not want RESTEasy to create JAXBContexts, you can plug-in your own by implementing an instance of javax.ws.rs.ext.ContextResolver

     

    
    public interface ContextResolver<T>
    {
       T getContext(Class<?> type);
    }
    
    @Produces("application/xml")
    @Provider
    public class MyJAXBContextResolver implements ContextResolver<JAXBContext>
    {
    
       JAXBContext getContext(Class<?> type)
       {
          if (type.equals(WhateverClassIsOverridedFor.class)) return JAXBContext.newInstance()...;
       }
    }
    

     

    You must provide a @Produces annotation to specify the media type the context is meant for.  You must also make sure to implement ContextResolver.  This helps the runtime match to the correct context resolver.  You must also annotate the ContextResolver class with @Provider.

     

    There are multiple ways to make this ContextResolver available. 

     

    1. Return it as a class or instance from a javax.ws.rs.core.Application implementation

    2. List it as a provider with resteasy.providers

    3. Let RESTEasy automatically scan for it within your WAR file. See Configuration Guide

    4. Manually add it via ResteasyProviderFactory.getInstance().registerProvider(Class) or registerProviderInstance(Object)