In order to deliver valid JSON double quotes have to be escaped. Boon does not appear to take this into account. There is a setting that does encoding of UTF-8 chars which will also take care of escaping by accident but would push decoding onto the receiving end. There is no way to leave the UTF-8 characters intact but still output escaped double quotes. The Gson parser does the right thing by default:
public class JsonTest {
public static final Gson GSON_DEFAULT = new Gson();
public static final ObjectMapper BOON_DEFAULT = JsonFactory.create();
public static final ObjectMapper BOON_ENCODING = JsonFactory.create(new JsonParserFactory(),
new JsonSerializerFactory().setEncodeStrings(false));
private class Wrapper {
public String test;
}
@Test
public void encodeQuote() {
Wrapper quote = new Wrapper();
quote.test = "boe \" aargh";
Wrapper utf8 = new Wrapper();
utf8.test = "Τη γλώσσα μου έδωσαν ελληνική";
System.out.println(GSON_DEFAULT.toJson(quote));
System.out.println(GSON_DEFAULT.toJson(utf8)+"\n");
System.out.println(BOON_DEFAULT.toJson(quote));
System.out.println(BOON_DEFAULT.toJson(utf8)+"\n");
System.out.println(BOON_ENCODING.toJson(quote));
System.out.println(BOON_ENCODING.toJson(utf8)+"\n");
}
}
In order to deliver valid JSON double quotes have to be escaped. Boon does not appear to take this into account. There is a setting that does encoding of UTF-8 chars which will also take care of escaping by accident but would push decoding onto the receiving end. There is no way to leave the UTF-8 characters intact but still output escaped double quotes. The Gson parser does the right thing by default:
output:
EDIT: Checked Jackson too, it behaves like Gson does