private static String generateJson(Object o, boolean prettyPrint, boolean escapeNonASCII) {
try {
StringWriter sw = new StringWriter();
JsonGenerator jgen = new JsonFactory(mapper()).createGenerator(sw);
if (prettyPrint) {
jgen.setPrettyPrinter(new DefaultPrettyPrinter());
}
if (escapeNonASCII) {
jgen.enable(Feature.ESCAPE_NON_ASCII);
}
mapper().writeValue(jgen, o);