public String marshal ( Object jaxbObject ) { // Precondition, check that the jaxbContext is set! if ( jaxbContext == null ) { logger . error ( "Trying to marshal with a null jaxbContext, returns null. Check your configuration, e.g. jaxb-transformers!" ) ; return null ; } try { StringWriter writer = new StringWriter ( ) ; Marshaller marshaller = jaxbContext . createMarshaller ( ) ; if ( marshallProps != null ) { for ( Entry < String , Object > entry : marshallProps . entrySet ( ) ) { marshaller . setProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } } marshaller . marshal ( jaxbObject , writer ) ; String xml = writer . toString ( ) ; if ( logger . isDebugEnabled ( ) ) logger . debug ( "marshalled jaxb object of type {}, returns xml: {}" , jaxbObject . getClass ( ) . getSimpleName ( ) , xml ) ; return xml ; } catch ( JAXBException e ) { throw new RuntimeException ( e ) ; } }
Marshal a JAXB object to a XML - string