jackson 返回前端的字符串中 引号 被自动加上反斜杆

数据库中存了一个json字段,如

{"networkNumber": 1}

读到 String 对象中,比如

class Dto {
  String data;
}

将这个 Dto 类用 jackson 自动转换后,前端得到的数据是加了引号的。

{\"networkNumber\": 1}

解决方法:

使用JsonNode

class DtoNew {
  JsonNode data;
}

ObjectMapper mapper = new ObjectMapper();
try {
    dtoNew.data =  mapper.readTree(   dto.data ));
} catch (IOException e) {
    e.printStackTrace();
}

 

你可能感兴趣的:(#,java,web,-,jackson)