marshaller = jaxbContext.createMarshaller();
if( prettyPrint ) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
}
} catch( JAXBException jaxbe ) {
throw new SerializationException("Unable to create JAXB marshaller", jaxbe);
}
try {
marshaller.setProperty(CharacterEscapeHandler.class.getName(), new CharacterEscapeHandler() {
public void escape(char[] ac, int i, int j, boolean flag, Writer writer) throws IOException {
writer.write( ac, i, j );
}
});
} catch (PropertyException e) {
throw new SerializationException("Unable to set CharacterEscapeHandler", e);
}
StringWriter stringWriter = new StringWriter();
try {
marshaller.marshal(object, stringWriter);
} catch( JAXBException jaxbe ) {
throw new SerializationException("Unable to marshall " + object.getClass().getSimpleName() + " instance.", jaxbe);
}
String output = stringWriter.toString();
return output;
}