Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

17.2. Pluggable JAXBContexts with ContextResolvers


We do not recommend using this feature unless you are familiar with the principles involved.
By default, RESTEasy creates and caches JAXBContext instances per class type depending on the class you are marshalling or unmarshalling. 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);
 }

 @Provider
 @Produces("application/xml")
 public class MyJAXBContextResolver implements ContextResolver<JAXBContext>
 {
JAXBContext getContext(Class<?> type)
{
   if (type.equals(WhateverClassIsOverridedFor.class)) return JAXBContext.newInstance()...;
}
 }
Copy to Clipboard Toggle word wrap
You must provide a @Produces annotation to specify the types of media intended for the context. You must also implement ContextResolver<JAXBContext>. This helps the runtime match the correct context resolver. You must also annotate the ContextResolver class with @Provider.
There are several 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 the Configuration Guide for more details.)
  4. add it manually via ResteasyProviderFactory.getInstance().registerProvider(Class) or registerProviderInstance(Object).
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat