Search in sources :

Example 1 with UnmarshalException

use of jakarta.xml.bind.UnmarshalException in project spring-framework by spring-projects.

the class Jaxb2XmlDecoder method unmarshal.

private Object unmarshal(List<XMLEvent> events, Class<?> outputClass) {
    try {
        Unmarshaller unmarshaller = initUnmarshaller(outputClass);
        XMLEventReader eventReader = StaxUtils.createXMLEventReader(events);
        if (outputClass.isAnnotationPresent(XmlRootElement.class)) {
            return unmarshaller.unmarshal(eventReader);
        } else {
            JAXBElement<?> jaxbElement = unmarshaller.unmarshal(eventReader, outputClass);
            return jaxbElement.getValue();
        }
    } catch (UnmarshalException ex) {
        throw new DecodingException("Could not unmarshal XML to " + outputClass, ex);
    } catch (JAXBException ex) {
        throw new CodecException("Invalid JAXB configuration", ex);
    }
}
Also used : UnmarshalException(jakarta.xml.bind.UnmarshalException) JAXBException(jakarta.xml.bind.JAXBException) XMLEventReader(javax.xml.stream.XMLEventReader) DecodingException(org.springframework.core.codec.DecodingException) CodecException(org.springframework.core.codec.CodecException) Unmarshaller(jakarta.xml.bind.Unmarshaller)

Aggregations

JAXBException (jakarta.xml.bind.JAXBException)1 UnmarshalException (jakarta.xml.bind.UnmarshalException)1 Unmarshaller (jakarta.xml.bind.Unmarshaller)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 CodecException (org.springframework.core.codec.CodecException)1 DecodingException (org.springframework.core.codec.DecodingException)1