Вы также можете посмотреть проект JAXBIntroductions , который предназначен для аналогичной цели. Конфигурация аннотации хранится в файле, не требуя изменения исходного кода. Он хорошо работает с Джерси, внедряя провайдера JAX-RS. Вы можете проверить мой блог запись , которая подробно объясняет это на примере. Вот простой JAXBContextResolver, предоставляющий JAXBIntroductions, который можно использовать в вашем приложении на Джерси.
import com.sun.xml.bind.api.JAXBRIContext;
import org.jboss.jaxb.intros.IntroductionsAnnotationReader;
import org.jboss.jaxb.intros.IntroductionsConfigParser;
import org.jboss.jaxb.intros.configmodel.JaxbIntros;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;
import java.util.*;
@Provider
public class JAXBContextResolverForJAXBIntroductions implements ContextResolver<JAXBContext> {
private final JAXBContext context;
private final Set<Class> types;
private final Class[] cTypes = {Customer.class};
public JAXBContextResolverForJAXBIntroductions() throws Exception {
this.types = new HashSet(Arrays.asList(cTypes));
JaxbIntros config = IntroductionsConfigParser.parseConfig(this.getClass().getResourceAsStream("/intro-config.xml"));
IntroductionsAnnotationReader reader = new IntroductionsAnnotationReader(config);
Map<String, Object> jaxbConfig = new HashMap<String, Object>();
jaxbConfig.put(JAXBRIContext.ANNOTATION_READER, reader);
this.context = JAXBContext.newInstance(cTypes, jaxbConfig);
}
public JAXBContext getContext(Class<?> objectType) {
return (types.contains(objectType)) ? context : null;
}
}