Package org.glassfish.jersey.message
Interface MessageBodyWorkers
-
- All Known Implementing Classes:
MessageBodyFactory
public interface MessageBodyWorkers
An injectable interface providing lookup ofMessageBodyReader
andMessageBodyWriter
instances.- See Also:
Context
,MessageBodyReader
,MessageBodyWriter
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> javax.ws.rs.ext.MessageBodyReader<T>
getMessageBodyReader(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
Get a message body reader that matches a set of criteria.<T> javax.ws.rs.ext.MessageBodyReader<T>
getMessageBodyReader(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
Get a message body reader that matches a set of criteria.java.util.List<javax.ws.rs.core.MediaType>
getMessageBodyReaderMediaTypes(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations)
Get the list of media types supported for a Java type.java.util.List<javax.ws.rs.core.MediaType>
getMessageBodyReaderMediaTypesByType(java.lang.Class<?> type)
Get the list of media types supported for a Java type.java.util.List<javax.ws.rs.ext.MessageBodyReader>
getMessageBodyReadersForType(java.lang.Class<?> type)
Get a list ofMessageBodyReader
s that are suitable for the giventype
.<T> javax.ws.rs.ext.MessageBodyWriter<T>
getMessageBodyWriter(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
Get a message body writer that matches a set of criteria.<T> javax.ws.rs.ext.MessageBodyWriter<T>
getMessageBodyWriter(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
Get a message body writer that matches a set of criteria.javax.ws.rs.core.MediaType
getMessageBodyWriterMediaType(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, java.util.List<javax.ws.rs.core.MediaType> acceptableMediaTypes)
Get the most acceptable media type supported for a Java type given a set of acceptable media types.java.util.List<javax.ws.rs.core.MediaType>
getMessageBodyWriterMediaTypes(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations)
Get the list of media types supported for a Java type.java.util.List<javax.ws.rs.core.MediaType>
getMessageBodyWriterMediaTypesByType(java.lang.Class<?> type)
Get the list of media types supported for a Java type.java.util.List<javax.ws.rs.ext.MessageBodyWriter>
getMessageBodyWritersForType(java.lang.Class<?> type)
Get a list ofMessageBodyWriter
s that are suitable for the giventype
.java.util.List<ReaderModel>
getReaderModelsForType(java.lang.Class<?> type)
Get a list ofMessageBodyReader
models that are suitable for the giventype
.java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyReader>>
getReaders(javax.ws.rs.core.MediaType mediaType)
Get the map of media type to list of message body writers that are compatible with a media type.java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyWriter>>
getWriters(javax.ws.rs.core.MediaType mediaType)
Get the map of media type to list of message body writers that are compatible with a media type.java.util.List<WriterModel>
getWritersModelsForType(java.lang.Class<?> type)
Get a list ofMessageBodyWriter
models that are suitable for the giventype
.java.lang.String
readersToString(java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyReader>> readers)
Convert a map media type to list of message body readers to a string.java.lang.Object
readFrom(java.lang.Class<?> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> httpHeaders, PropertiesDelegate propertiesDelegate, java.io.InputStream entityStream, java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors, boolean translateNce)
Reads a type from theentityStream
using interceptors.java.lang.String
writersToString(java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyWriter>> writers)
Convert a map media type to list of message body writers to a string.java.io.OutputStream
writeTo(java.lang.Object entity, java.lang.Class<?> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> httpHeaders, PropertiesDelegate propertiesDelegate, java.io.OutputStream entityStream, java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors)
Writers a type to theentityStream
using interceptors.
-
-
-
Method Detail
-
getReaders
java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyReader>> getReaders(javax.ws.rs.core.MediaType mediaType)
Get the map of media type to list of message body writers that are compatible with a media type.- Parameters:
mediaType
- the compatible media type.- Returns:
- the map of media type to list of message body writers.
-
getWriters
java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyWriter>> getWriters(javax.ws.rs.core.MediaType mediaType)
Get the map of media type to list of message body writers that are compatible with a media type.- Parameters:
mediaType
- the compatible media type.- Returns:
- the map of media type to list of message body writers.
-
readersToString
java.lang.String readersToString(java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyReader>> readers)
Convert a map media type to list of message body readers to a string.- Parameters:
readers
- the map media type to list of message body readers- Returns:
- the string representation.
-
writersToString
java.lang.String writersToString(java.util.Map<javax.ws.rs.core.MediaType,java.util.List<javax.ws.rs.ext.MessageBodyWriter>> writers)
Convert a map media type to list of message body writers to a string.- Parameters:
writers
- the map media type to list of message body readers- Returns:
- the string representation.
-
getMessageBodyReader
<T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
Get a message body reader that matches a set of criteria.- Type Parameters:
T
- the type of object to be read.- Parameters:
type
- the class of object 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, this will be compared to the values ofConsumes
for each candidate reader and only matching readers will be queried.- Returns:
- a MessageBodyReader that matches the supplied criteria or null if none is found.
-
getMessageBodyReader
<T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
Get a message body reader that matches a set of criteria.- Type Parameters:
T
- the type of object to be read.- Parameters:
type
- the class of object 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, this will be compared to the values ofConsumes
for each candidate reader and only matching readers will be queried.propertiesDelegate
- request-scoped properties delegate.- Returns:
- a MessageBodyReader that matches the supplied criteria or null if none is found.
-
getMessageBodyWriter
<T> javax.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
Get a message body writer that matches a set of criteria.- Type Parameters:
T
- the type of the object that is to be written.- Parameters:
type
- the class of 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, this will be compared to the values ofProduces
for each candidate writer and only matching writers will be queried.- Returns:
- a MessageBodyReader that matches the supplied criteria or null if none is found.
-
getMessageBodyWriter
<T> javax.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
Get a message body writer that matches a set of criteria.- Type Parameters:
T
- the type of the object that is to be written.- Parameters:
type
- the class of 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, this will be compared to the values ofProduces
for each candidate writer and only matching writers will be queried.propertiesDelegate
- request-scoped properties delegate.- Returns:
- a MessageBodyReader that matches the supplied criteria or null if none is found.
-
getMessageBodyReaderMediaTypes
java.util.List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypes(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations)
Get the list of media types supported for a Java type.- Parameters:
type
- the class of object that is to be read.genericType
- the type of object to be read. E.g. if the message body is to be read as a method parameter, this will be the declared type of the parameter as returned byMethod.getGenericParameterTypes
.annotations
- an array of the annotations on the declaration of the artifact that will be read. E.g. if the message body is to be consumed as a method parameter, this will be the annotations on that parameter returned byMethod.getParameterAnnotations
.- Returns:
- the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
-
getMessageBodyReaderMediaTypesByType
java.util.List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypesByType(java.lang.Class<?> type)
Get the list of media types supported for a Java type.- Parameters:
type
- the class of object that is to be read.- Returns:
- the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
-
getMessageBodyReadersForType
java.util.List<javax.ws.rs.ext.MessageBodyReader> getMessageBodyReadersForType(java.lang.Class<?> type)
Get a list ofMessageBodyReader
s that are suitable for the giventype
. The list is sorted based on the class hierarchy (most specific readers are first).- Parameters:
type
- the class of object readers are requested for.- Returns:
- the list of supported
MessageBodyReader
s for given class.
-
getReaderModelsForType
java.util.List<ReaderModel> getReaderModelsForType(java.lang.Class<?> type)
Get a list ofMessageBodyReader
models that are suitable for the giventype
. The list is sorted based on the class hierarchy (most specific readers are first).- Parameters:
type
- the class of object readers are requested for.- Returns:
- the list of supported
MessageBodyReader
models for given class. - Since:
- 2.16
-
getMessageBodyWriterMediaTypes
java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypes(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations)
Get the list of media types supported for a Java type.- Parameters:
type
- the class of 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
.- Returns:
- the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
-
getMessageBodyWriterMediaTypesByType
java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypesByType(java.lang.Class<?> type)
Get the list of media types supported for a Java type.- Parameters:
type
- the class of object that is to be written.- Returns:
- the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
-
getMessageBodyWritersForType
java.util.List<javax.ws.rs.ext.MessageBodyWriter> getMessageBodyWritersForType(java.lang.Class<?> type)
Get a list ofMessageBodyWriter
s that are suitable for the giventype
. The list is sorted based on the class hierarchy (most specific writers are first).- Parameters:
type
- the class of object writers are requested for.- Returns:
- the list of supported
MessageBodyWriter
s for given class.
-
getWritersModelsForType
java.util.List<WriterModel> getWritersModelsForType(java.lang.Class<?> type)
Get a list ofMessageBodyWriter
models that are suitable for the giventype
. The list is sorted based on the class hierarchy (most specific writers are first).- Parameters:
type
- the class of object writers are requested for.- Returns:
- the list of supported
MessageBodyWriter
models for given class. - Since:
- 2.16
-
getMessageBodyWriterMediaType
javax.ws.rs.core.MediaType getMessageBodyWriterMediaType(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, java.util.List<javax.ws.rs.core.MediaType> acceptableMediaTypes)
Get the most acceptable media type supported for a Java type given a set of acceptable media types.- Parameters:
type
- the class of 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
.acceptableMediaTypes
- the list of acceptable media types, sorted according to the quality with the media type of highest quality occurring first first.- Returns:
- the best media types
-
readFrom
java.lang.Object readFrom(java.lang.Class<?> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> httpHeaders, PropertiesDelegate propertiesDelegate, java.io.InputStream entityStream, java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors, boolean translateNce) throws javax.ws.rs.WebApplicationException, java.io.IOException
Reads a type from theentityStream
using interceptors. If the parameterintercept
is true thenreader interceptors
are executed before calling themessage body reader
. The appropriatemessage body reader
is chosen after the interceptor execution based on parameter passed to this method and modified by the interceptors.- Parameters:
rawType
- raw Java entity type.type
- generic Java entity type.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 byMethod.getParameterAnnotations
.mediaType
- the media type of the HTTP entity.httpHeaders
- the mutable HTTP headers associated with HTTP entity.propertiesDelegate
- request-scoped properties delegate.entityStream
- theInputStream
of the HTTP entity. The stream is not closed after reading the entity.readerInterceptors
- Reader interceptor that are to be used to intercept the reading of an entity. The interceptors will be executed in the same order as given in this parameter.translateNce
- iftrue
, theNoContentException
thrown by a selected message body reader will be translated into aBadRequestException
as required by JAX-RS specification on the server side.- Returns:
- the entity that was read from the
entityStream
. - Throws:
javax.ws.rs.WebApplicationException
- Thrown whenmessage body reader
fails.java.io.IOException
- Thrown when reading from theentityStream
fails.
-
writeTo
java.io.OutputStream writeTo(java.lang.Object entity, java.lang.Class<?> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> httpHeaders, PropertiesDelegate propertiesDelegate, java.io.OutputStream entityStream, java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors) throws java.io.IOException, javax.ws.rs.WebApplicationException
Writers a type to theentityStream
using interceptors. If the parameterintercept
is true thenwriter interceptors
are executed before calling themessage body writer
. The appropriatemessage body writer
is chosen after the interceptor execution based on parameter passed to this method and modified by the interceptors.- Parameters:
entity
- Entity to be written to the entityStreamrawType
- raw Java entity type.type
- generic Java entity type.annotations
- an array of the annotations on the resource method that returns the object.mediaType
- the media type of the HTTP entity.httpHeaders
- the mutable HTTP headers associated with HTTP entity.propertiesDelegate
- request-scoped properties delegate.entityStream
- theOutputStream
for the HTTP entity.writerInterceptors
- Writer interceptor that are to be used to intercept the writing of an entity. The interceptors will be executed in the same order as given in this parameter.- Returns:
- Outer output stream that should be closed by the caller.
- Throws:
javax.ws.rs.WebApplicationException
- Thrown whenmessage body reader
fails.java.io.IOException
- Thrown when reading from theentityStream
fails.
-
-