@SuppressWarnings("unchecked")
    public <T> T readBodyAsObject(Class<T> type) {
        Charset charset = readCharset();
        InputStream inputStream = new ByteArrayInputStream(message.getBodyContent());
        InputStreamReader inputReader = new InputStreamReader(inputStream, charset);
        StreamSource streamSource = new StreamSource(inputReader);
        try {
            Unmarshaller unmarshaller = JAXBContext.newInstance(type).createUnmarshaller();
            if (type.isAnnotationPresent(XmlRootElement.class)) {
                return (T)unmarshaller.unmarshal(streamSource);
            } else {
                JAXBElement<T> element = unmarshaller.unmarshal(streamSource, type);
                return element.getValue();
            }
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
@ SuppressWarnings ( "unchecked" ) public < T > T readBodyAsObject ( Class < T > type ) { Charset charset = readCharset ( ) ; InputStream inputStream = new ByteArrayInputStream ( message . getBodyContent ( ) ) ; InputStreamReader inputReader = new InputStreamReader ( inputStream , charset ) ; StreamSource streamSource = new StreamSource ( inputReader ) ; try { Unmarshaller unmarshaller = JAXBContext . newInstance ( type ) . createUnmarshaller ( ) ; if ( type . isAnnotationPresent ( XmlRootElement . class ) ) { return ( T ) unmarshaller . unmarshal ( streamSource ) ; } else { JAXBElement < T > element = unmarshaller . unmarshal ( streamSource , type ) ; return element . getValue ( ) ; } } catch ( JAXBException e ) { throw new RuntimeException ( e ) ; } }
Extracts the message body and interprets it as
the XML representation of an object of the given
type.

@param type The type (class) of the object
@return The message body as an object of the specified type