Class AbstractJaxbElementProvider

java.lang.Object
org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider<T>
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider<jakarta.xml.bind.JAXBElement<?>>
org.glassfish.jersey.jaxb.internal.AbstractJaxbElementProvider
All Implemented Interfaces:
MessageBodyReader<jakarta.xml.bind.JAXBElement<?>>, MessageBodyWriter<jakarta.xml.bind.JAXBElement<?>>
Direct Known Subclasses:
XmlJaxbElementProvider

public abstract class AbstractJaxbElementProvider extends AbstractJaxbProvider<jakarta.xml.bind.JAXBElement<?>>
An abstract provider for JAXBElement.

Implementing classes may extend this class to provide specific marshalling and unmarshalling behaviour.

When unmarshalling a UnmarshalException will result in a WebApplicationException being thrown with a status of 400 (Client error), and a JAXBException will result in a WebApplicationException being thrown with a status of 500 (Internal Server error).

When marshalling a JAXBException will result in a WebApplicationException being thrown with a status of 500 (Internal Server error).

Author:
Paul Sandoz, Marek Potociar
  • Constructor Details

    • AbstractJaxbElementProvider

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

      public AbstractJaxbElementProvider(Providers providers, MediaType resolverMediaType)
      Inheritance constructor.
      Parameters:
      providers - JAX-RS providers.
      resolverMediaType - JAXB component context resolver media type to be used.
  • Method Details

    • isReadable

      public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
    • isWriteable

      public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
    • readFrom

      public final jakarta.xml.bind.JAXBElement<?> readFrom(Class<jakarta.xml.bind.JAXBElement<?>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,String> httpHeaders, InputStream inputStream) throws IOException
      Throws:
      IOException
    • readFrom

      protected abstract jakarta.xml.bind.JAXBElement<?> readFrom(Class<?> type, MediaType mediaType, jakarta.xml.bind.Unmarshaller unmarshaller, InputStream entityStream) throws jakarta.xml.bind.JAXBException
      Read JAXB element from an entity stream.
      Parameters:
      type - the type that is to be read from the entity stream.
      mediaType - the media type of the HTTP entity.
      unmarshaller - JAXB unmarshaller to be used.
      entityStream - the InputStream of the HTTP entity. The caller is responsible for ensuring that the input stream ends when the entity has been consumed. The implementation should not close the input stream.
      Returns:
      JAXB element representing the entity.
      Throws:
      jakarta.xml.bind.JAXBException - in case entity unmarshalling fails.
    • writeTo

      public final void writeTo(jakarta.xml.bind.JAXBElement<?> t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,Object> httpHeaders, OutputStream entityStream) throws IOException
      Throws:
      IOException
    • writeTo

      protected abstract void writeTo(jakarta.xml.bind.JAXBElement<?> element, MediaType mediaType, Charset charset, jakarta.xml.bind.Marshaller marshaller, OutputStream entityStream) throws jakarta.xml.bind.JAXBException
      Write JAXB element to an entity stream.
      Parameters:
      element - JAXB element to be written to an entity stream.
      mediaType - the media type of the HTTP entity.
      charset - character set to be used.
      marshaller - JAXB unmarshaller to be used.
      entityStream - the InputStream of the HTTP entity. The caller is responsible for ensuring that the input stream ends when the entity has been consumed. The implementation should not close the input stream.
      Throws:
      jakarta.xml.bind.JAXBException - in case entity marshalling fails.