-
public interface Providers
An injectable interface providing runtime lookup of provider instances.- Since:
- 1.0
- Author:
- Paul Sandoz, Marc Hadley
- See Also:
Context
,MessageBodyReader
,MessageBodyWriter
,ContextResolver
,ExceptionMapper
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description <T> ContextResolver<T>
getContextResolver(Class<T> contextType, MediaType mediaType)
Get a context resolver for a particular type of context and media type.<T extends Throwable>
ExceptionMapper<T>getExceptionMapper(Class<T> type)
Get an exception mapping provider for a particular class of exception.<T> MessageBodyReader<T>
getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)
Get a message body reader that matches a set of criteria.<T> MessageBodyWriter<T>
getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)
Get a message body writer that matches a set of criteria.
-
-
-
Method Detail
-
getMessageBodyReader
<T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)
Get a message body reader that matches a set of criteria. The set of readers is first filtered by comparing the supplied value ofmediaType
with the value of each reader'sConsumes
, ensuring the supplied value oftype
is assignable to the generic type of the reader, and eliminating those that do not match. The list of matching readers is then ordered with those with the best matching values ofConsumes
(x/y > x/* > */*) sorted first. Finally, theMessageBodyReader.isReadable(Class, Type, Annotation[], MediaType)
method is called on each reader in order using the supplied criteria and the first reader that returnstrue
is selected and returned.- Type Parameters:
T
- type of the the object that is to be read.- Parameters:
type
- the class of the object that is to be read.genericType
- the type of object to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned byClass.getGenericParameterTypes
.annotations
- an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned byClass.getParameterAnnotations
.mediaType
- the media type of the data that will be read.- Returns:
- a MessageBodyReader that matches the supplied criteria or
null
if none is found.
-
getMessageBodyWriter
<T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)
Get a message body writer that matches a set of criteria. The set of writers is first filtered by comparing the supplied value ofmediaType
with the value of each writer'sProduces
, ensuring the supplied value oftype
is assignable to the generic type of the reader, and eliminating those that do not match. The list of matching writers is then ordered with those with the best matching values ofProduces
(x/y > x/* > */*) sorted first. Finally, theMessageBodyWriter.isWriteable(Class, Type, Annotation[], MediaType)
method is called on each writer in order using the supplied criteria and the first writer that returnstrue
is selected and returned.- Type Parameters:
T
- type of the object that is to be written.- Parameters:
type
- the class of the object that is to be written.genericType
- the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned byField.getGenericType
.annotations
- an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned byField.getDeclaredAnnotations
.mediaType
- the media type of the data that will be written.- Returns:
- a MessageBodyReader that matches the supplied criteria or
null
if none is found.
-
getExceptionMapper
<T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type)
Get an exception mapping provider for a particular class of exception. Returns the provider whose generic type is the nearest superclass oftype
.- Type Parameters:
T
- type of the exception handled by the exception mapping provider.- Parameters:
type
- the class of exception.- Returns:
- an
ExceptionMapper
for the supplied type ornull
if none is found.
-
getContextResolver
<T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType)
Get a context resolver for a particular type of context and media type. The set of resolvers is first filtered by comparing the supplied value ofmediaType
with the value of each resolver'sProduces
, ensuring the generic type of the context resolver is assignable to the supplied value ofcontextType
, and eliminating those that do not match. If only one resolver matches the criteria then it is returned. If more than one resolver matches then the list of matching resolvers is ordered with those with the best matching values ofProduces
(x/y > x/* > */*) sorted first. A proxy is returned that delegates calls toContextResolver.getContext(java.lang.Class)
to each matching context resolver in order and returns the first non-null value it obtains or null if all matching context resolvers return null.- Type Parameters:
T
- type of the context.- Parameters:
contextType
- the class of context desired.mediaType
- the media type of data for which a context is required.- Returns:
- a matching context resolver instance or
null
if no matching context providers are found.
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/ws/rs/ext/Providers.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.