Class AbstractJaxb2PayloadMethodProcessor

All Implemented Interfaces:
MethodArgumentResolver, MethodReturnValueHandler
Direct Known Subclasses:
JaxbElementPayloadMethodProcessor, XmlRootElementPayloadMethodProcessor

public abstract class AbstractJaxb2PayloadMethodProcessor extends AbstractPayloadMethodProcessor
Abstract base class for MethodArgumentResolver and MethodReturnValueHandler implementations that use JAXB2. Creates JAXBContext object lazily, and offers marshalling and unmarshalling methods.
Since:
2.0
Author:
Arjen Poutsma
  • Constructor Details

    • AbstractJaxb2PayloadMethodProcessor

      public AbstractJaxb2PayloadMethodProcessor()
  • Method Details

    • handleReturnValue

      public final void handleReturnValue(MessageContext messageContext, org.springframework.core.MethodParameter returnType, Object returnValue) throws Exception
      Description copied from interface: MethodReturnValueHandler
      Handles the given return value.
      Parameters:
      messageContext - the current message context
      returnType - the return type to handle. This type must have previously been passed to the MethodReturnValueHandler.supportsReturnType(MethodParameter) method of this interface, which must have returned true.
      returnValue - the return value to handle
      Throws:
      Exception - in case of errors
    • handleReturnValueInternal

      protected abstract void handleReturnValueInternal(MessageContext messageContext, org.springframework.core.MethodParameter returnType, Object returnValue) throws Exception
      Throws:
      Exception
    • marshalToResponsePayload

      protected final void marshalToResponsePayload(MessageContext messageContext, Class<?> clazz, Object jaxbElement) throws jakarta.xml.bind.JAXBException
      Marshals the given jaxbElement to the response payload of the given message context.
      Parameters:
      messageContext - the message context to marshal to
      clazz - the clazz to create a marshaller for
      jaxbElement - the object to be marshalled
      Throws:
      jakarta.xml.bind.JAXBException - in case of JAXB2 errors
    • unmarshalFromRequestPayload

      protected final Object unmarshalFromRequestPayload(MessageContext messageContext, Class<?> clazz) throws jakarta.xml.bind.JAXBException
      Unmarshals the request payload of the given message context.
      Parameters:
      messageContext - the message context to unmarshal from
      clazz - the class to unmarshal
      Returns:
      the unmarshalled object, or null if the request has no payload
      Throws:
      jakarta.xml.bind.JAXBException - in case of JAXB2 errors
    • unmarshalElementFromRequestPayload

      protected final <T> jakarta.xml.bind.JAXBElement<T> unmarshalElementFromRequestPayload(MessageContext messageContext, Class<T> clazz) throws jakarta.xml.bind.JAXBException
      Unmarshals the request payload of the given message context as JAXBElement.
      Parameters:
      messageContext - the message context to unmarshal from
      clazz - the class to unmarshal
      Returns:
      the unmarshalled element, or null if the request has no payload
      Throws:
      jakarta.xml.bind.JAXBException - in case of JAXB2 errors
    • createMarshaller

      protected jakarta.xml.bind.Marshaller createMarshaller(jakarta.xml.bind.JAXBContext jaxbContext) throws jakarta.xml.bind.JAXBException
      Creates a new Marshaller to be used for marshalling objects to XML. Defaults to JAXBContext.createMarshaller(), but can be overridden in subclasses for further customization.
      Parameters:
      jaxbContext - the JAXB context to create a marshaller for
      Returns:
      the marshaller
      Throws:
      jakarta.xml.bind.JAXBException - in case of JAXB errors
    • createUnmarshaller

      protected jakarta.xml.bind.Unmarshaller createUnmarshaller(jakarta.xml.bind.JAXBContext jaxbContext) throws jakarta.xml.bind.JAXBException
      Creates a new Unmarshaller to be used for unmarshalling XML to objects. Defaults to JAXBContext.createUnmarshaller(), but can be overridden in subclasses for further customization.
      Parameters:
      jaxbContext - the JAXB context to create a unmarshaller for
      Returns:
      the unmarshaller
      Throws:
      jakarta.xml.bind.JAXBException - in case of JAXB errors