79187268

Date: 2024-11-14 03:00:38
Score: 2.5
Natty:
Report link

Thank you @Thomas Boje / @Joachim Sauer,

    @Override
    public void run(String... args) throws Exception {
        final ObjectMapper jackson = new ObjectMapper();
        
        final ObjectNode objectNode = jackson.createObjectNode();
        String text = "Simplified Chinese 简体中文";

        // Enable escaping for non-ASCII characters, which is disabled by default
        jackson.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
        
        //no need to escape by ourselves, jackson will handle it after we enable the ESCAPE_NON_ASCII feature.
        //final String escapedInUnicodeText = StringEscapeUtils.escapeJava(text);
        //System.out.println(escapedInUnicodeText);
        //output is: Simplified Chinese \u7B80\u4F53\u4E2D\u6587
        
        objectNode.put("text", text);
        System.out.println(jackson.writeValueAsString(objectNode));
        //output is  {"text":"Simplified Chinese \u7B80\u4F53\u4E2D\u6587"}
    }
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Thomas
  • User mentioned (0): @Joachim
  • Self-answer (0.5):
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: ildvzg68472