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:
MessageBodyReader<T>
,MessageBodyWriter<T>
- Direct Known Subclasses:
AbstractCollectionJaxbProvider
,AbstractJaxbElementProvider
,AbstractRootElementJaxbProvider
,XmlRootObjectJaxbProvider
public abstract class AbstractJaxbProvider<T> extends AbstractMessageReaderWriterProvider<T>
A base class for implementing JAXB-based readers and writers.- Author:
- Paul Sandoz, Marek Potociar
-
-
Field Summary
-
Fields inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
UTF8
-
-
Constructor Summary
Constructors Constructor Description AbstractJaxbProvider(Providers providers)
Inheritance constructor.AbstractJaxbProvider(Providers providers, MediaType resolverMediaType)
Inheritance constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected jakarta.xml.bind.Marshaller
getMarshaller(Class type, 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 jakarta.xml.bind.JAXBContext
getStoredJaxbContext(Class type)
Retrieve cached JAXB context capable of handling the given Java type.protected jakarta.xml.bind.Unmarshaller
getUnmarshaller(Class type, MediaType mediaType)
Get the JAXB unmarshaller for the given class and media type.protected boolean
isFormattedOutput()
protected boolean
isSupported(MediaType mediaType)
Check if the given media type is supported by this JAXB entity provider.protected boolean
isXmlRootElementProcessing()
void
setConfiguration(Configuration config)
protected void
setHeader(jakarta.xml.bind.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 jakarta.ws.rs.ext.MessageBodyReader
isReadable, readFrom
-
Methods inherited from interface jakarta.ws.rs.ext.MessageBodyWriter
isWriteable, writeTo
-
-
-
-
Constructor Detail
-
AbstractJaxbProvider
public AbstractJaxbProvider(Providers providers)
Inheritance constructor.- Parameters:
providers
- JAX-RS providers.
-
-
Method Detail
-
setConfiguration
@Context public void setConfiguration(Configuration config)
-
isSupported
protected boolean isSupported(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 jakarta.xml.bind.Unmarshaller getUnmarshaller(Class type, MediaType mediaType) throws jakarta.xml.bind.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:
jakarta.xml.bind.JAXBException
- in case retrieving the unmarshaller fails with a JAXB exception.
-
getMarshaller
protected final jakarta.xml.bind.Marshaller getMarshaller(Class type, MediaType mediaType) throws jakarta.xml.bind.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:
jakarta.xml.bind.JAXBException
- in case retrieving the marshaller fails with a JAXB exception.
-
getStoredJaxbContext
protected jakarta.xml.bind.JAXBContext getStoredJaxbContext(Class type) throws jakarta.xml.bind.JAXBException
Retrieve cached JAXB context capable of handling the given Java type.- Parameters:
type
- Java type .- Returns:
- JAXB context associated with the Java type.
- Throws:
jakarta.xml.bind.JAXBException
- in case the JAXB context retrieval fails.
-
getSAXSource
protected static SAXSource getSAXSource(SAXParserFactory spf, InputStream entityStream) throws jakarta.xml.bind.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:
jakarta.xml.bind.JAXBException
- in case SAX source creation fails.
-
isFormattedOutput
protected boolean isFormattedOutput()
-
isXmlRootElementProcessing
protected boolean isXmlRootElementProcessing()
-
setHeader
protected void setHeader(jakarta.xml.bind.Marshaller marshaller, Annotation[] annotations)
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.
-
-