Class AbstractJaxbProvider<T>
java.lang.Object
org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider<T>
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider<T>
- Type Parameters:
T
- Java type supported by the provider.
- All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<T>
,javax.ws.rs.ext.MessageBodyWriter<T>
- Direct Known Subclasses:
AbstractCollectionJaxbProvider
,AbstractJaxbElementProvider
,AbstractRootElementJaxbProvider
,XmlRootObjectJaxbProvider
A base class for implementing JAXB-based readers and writers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private static final Map<Class<?>,
WeakReference<JAXBContext>> private final javax.ws.rs.ext.Providers
private final Value<javax.ws.rs.ext.ContextResolver<JAXBContext>>
private final Value<javax.ws.rs.ext.ContextResolver<Marshaller>>
private final Value<javax.ws.rs.ext.ContextResolver<Unmarshaller>>
Fields inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
UTF8
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractJaxbProvider
(javax.ws.rs.ext.Providers providers) Inheritance constructor.AbstractJaxbProvider
(javax.ws.rs.ext.Providers providers, javax.ws.rs.core.MediaType resolverMediaType) Inheritance constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate JAXBContext
getJAXBContext
(Class type) private JAXBContext
getJAXBContext
(Class type, javax.ws.rs.core.MediaType mt) private Marshaller
getMarshaller
(Class type) protected final Marshaller
getMarshaller
(Class type, javax.ws.rs.core.MediaType mediaType) Get the JAXB marshaller for the given class and media type.protected static SAXSource
getSAXSource
(SAXParserFactory spf, InputStream entityStream) Create newSAXSource
for a given entity input stream.protected JAXBContext
getStoredJaxbContext
(Class type) Retrieve cached JAXB context capable of handling the given Java type.private Unmarshaller
getUnmarshaller
(Class type) protected final Unmarshaller
getUnmarshaller
(Class type, javax.ws.rs.core.MediaType mediaType) Get the JAXB unmarshaller for the given class and media type.protected boolean
protected boolean
isSupported
(javax.ws.rs.core.MediaType mediaType) Check if the given media type is supported by this JAXB entity provider.protected boolean
void
setConfiguration
(javax.ws.rs.core.Configuration config) protected void
setHeader
(Marshaller marshaller, Annotation[] annotations) Set the custom XML header on a JAXB marshaller if specified viaXmlHeader
annotation, present in the supplied array of annotations.Methods inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
getCharset, getSize, readFromAsString, writeTo, writeTo, writeToAsString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.ws.rs.ext.MessageBodyReader
isReadable, readFrom
Methods inherited from interface javax.ws.rs.ext.MessageBodyWriter
isWriteable, writeTo
-
Field Details
-
jaxbContexts
-
jaxrsProviders
private final javax.ws.rs.ext.Providers jaxrsProviders -
fixedResolverMediaType
private final boolean fixedResolverMediaType -
mtContext
-
mtUnmarshaller
-
mtMarshaller
-
formattedOutput
-
xmlRootElementProcessing
-
-
Constructor Details
-
AbstractJaxbProvider
public AbstractJaxbProvider(javax.ws.rs.ext.Providers providers) Inheritance constructor.- Parameters:
providers
- JAX-RS providers.
-
AbstractJaxbProvider
public AbstractJaxbProvider(javax.ws.rs.ext.Providers providers, javax.ws.rs.core.MediaType resolverMediaType) Inheritance constructor.- Parameters:
providers
- JAX-RS providers.resolverMediaType
- JAXB component context resolver media type to be used.
-
-
Method Details
-
setConfiguration
@Context public void setConfiguration(javax.ws.rs.core.Configuration config) -
isSupported
protected boolean isSupported(javax.ws.rs.core.MediaType mediaType) Check if the given media type is supported by this JAXB entity provider.Subclasses can override this method. Default implementation always returns
true
.- Parameters:
mediaType
- media type to be checked for support.- Returns:
true
if the media type is supported by the entity provider,false
otherwise.
-
getUnmarshaller
protected final Unmarshaller getUnmarshaller(Class type, javax.ws.rs.core.MediaType mediaType) throws JAXBException Get the JAXB unmarshaller for the given class and media type.In case this provider instance has been
created with a fixed resolver media type
, the supplied media type argument will be ignored.- Parameters:
type
- Java type to be unmarshalled.mediaType
- entity media type.- Returns:
- JAXB unmarshaller for the requested Java type, media type combination.
- Throws:
JAXBException
- in case retrieving the unmarshaller fails with a JAXB exception.
-
getUnmarshaller
- Throws:
JAXBException
-
getMarshaller
protected final Marshaller getMarshaller(Class type, javax.ws.rs.core.MediaType mediaType) throws JAXBException Get the JAXB marshaller for the given class and media type.In case this provider instance has been
created with a fixed resolver media type
, the supplied media type argument will be ignored.- Parameters:
type
- Java type to be marshalled.mediaType
- entity media type.- Returns:
- JAXB marshaller for the requested Java type, media type combination.
- Throws:
JAXBException
- in case retrieving the marshaller fails with a JAXB exception.
-
getMarshaller
- Throws:
JAXBException
-
getJAXBContext
- Throws:
JAXBException
-
getJAXBContext
- Throws:
JAXBException
-
getStoredJaxbContext
Retrieve cached JAXB context capable of handling the given Java type.- Parameters:
type
- Java type .- Returns:
- JAXB context associated with the Java type.
- Throws:
JAXBException
- in case the JAXB context retrieval fails.
-
getSAXSource
protected static SAXSource getSAXSource(SAXParserFactory spf, InputStream entityStream) throws JAXBException Create newSAXSource
for a given entity input stream.- Parameters:
spf
- SAX parser factory to be used to create the SAX source.entityStream
- entity input stream.- Returns:
- new
SAXSource
representing the entity input stream. - Throws:
JAXBException
- in case SAX source creation fails.
-
isFormattedOutput
protected boolean isFormattedOutput() -
isXmlRootElementProcessing
protected boolean isXmlRootElementProcessing() -
setHeader
Set the custom XML header on a JAXB marshaller if specified viaXmlHeader
annotation, present in the supplied array of annotations.- Parameters:
marshaller
- JAXB marshaller.annotations
- array of annotations that MAY contain aXmlHeader
annotation instance.
-