Class 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 Detail

      • AbstractJaxbElementProvider

        public AbstractJaxbElementProvider​(Providers providers,
                                           Configuration config)
        Inheritance constructor.
        Parameters:
        providers - JAX-RS providers.
      • AbstractJaxbElementProvider

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

      • 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

        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.