我想在写字符串时删除转义字符。我的代码如下。
private static ObjectMapper objectMapper = new ObjectMapper();
public static JsonNode MyMethod()
{
InputStream cleanUp = TestHelper.class.getClassLoader().getResourceAsStream("file.txt");
message = new String(cleanUp.readAllBytes());
objectMapper.getFactory().configure(JsonWriteFeature.ESCAPE_NON_ASCII.mappedFeature(),false);
root = objectMapper.readTree(new File("filePath"));
((ObjectNode) root).put("message", message );
return root;
}
包含的file.txt
[{\n \"timestamp\": 1599456392538
预期的 :
"[{\n \"timestamp\": 1599456392538"
实际的 :
"[{\\n \\\"timestamp\\\": 1599456392538"