Write ObjectNode to JSON String with UTF-8 Characters to Escaped ASCII

You should enable the JsonGenerator feature which controls the escaping of the non-ASCII characters. Here is an example:

    ObjectMapper mapper = new ObjectMapper();
    mapper.getFactory().configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
    ObjectNode node = mapper.getNodeFactory().objectNode();
    node.put("field1", "Maël Hörz");
    System.out.println(mapper.writeValueAsString(node));

The output is:

{"field1":"Ma\u00EBl H\u00F6rz"}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)