Class AbstractRootElementJaxbProvider

  • All Implemented Interfaces:
    MessageBodyReader<Object>, MessageBodyWriter<Object>
    Direct Known Subclasses:
    XmlRootElementJaxbProvider

    public abstract class AbstractRootElementJaxbProvider
    extends AbstractJaxbProvider<Object>
    An abstract provider for JAXB types that are annotated with XmlRootElement or XmlType.

    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

      • AbstractRootElementJaxbProvider

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

        public AbstractRootElementJaxbProvider​(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 Object readFrom​(Class<Object> type,
                                  MediaType mediaType,
                                  jakarta.xml.bind.Unmarshaller u,
                                  InputStream entityStream)
                           throws jakarta.xml.bind.JAXBException
        Unmarshal a JAXB type.

        Implementing classes may override this method.

        Parameters:
        type - the JAXB type
        mediaType - the media type
        u - the unmarshaller to use for unmarshalling.
        entityStream - the input stream to unmarshal from.
        Returns:
        an instance of the JAXB type.
        Throws:
        jakarta.xml.bind.JAXBException - in case the JAXB unmarshalling fails.
      • writeTo

        protected void writeTo​(Object t,
                               MediaType mediaType,
                               Charset c,
                               jakarta.xml.bind.Marshaller m,
                               OutputStream entityStream)
                        throws jakarta.xml.bind.JAXBException
        Marshal an instance of a JAXB type.

        Implementing classes may override this method.

        Parameters:
        t - the instance of the JAXB type.
        mediaType - the media type.
        c - the character set to serialize characters to.
        m - the marshaller to marshaller the instance of the JAXB type.
        entityStream - the output stream to marshal to.
        Throws:
        jakarta.xml.bind.JAXBException - in case the JAXB marshalling fails.