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
  • Constructor Details

    • AbstractJaxbProvider

      public AbstractJaxbProvider(Providers providers)
      Inheritance constructor.
      Parameters:
      providers - JAX-RS providers.
    • AbstractJaxbProvider

      public AbstractJaxbProvider(Providers providers, 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(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 new SAXSource 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 via XmlHeader annotation, present in the supplied array of annotations.
      Parameters:
      marshaller - JAXB marshaller.
      annotations - array of annotations that MAY contain a XmlHeader annotation instance.