@Autowired
ObjectMapper objectMapper;

//实体转json


  String data = "";  //一个json串


  Student stu = new Student ();


 stu = objectMapper.readValue(data, Student .class);// json字符串转实体


public
<T> String writeAsString(T t) throws JsonProcessingException { return objectMapper.writeValueAsString(t); } String aa = writeAsString(stu);

 

//json转实体

    public <T> T readValue(String data) {
        try {
            return objectMapper.readValue(data, new TypeReference<T>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return null;
    }

 

相关文章:

  • 2021-12-31
  • 2022-01-21
  • 2022-02-07
  • 2022-01-19
  • 2022-02-07
  • 2021-11-28
  • 2021-11-28
  • 2021-12-20
猜你喜欢
  • 2021-07-21
  • 2022-12-23
  • 2022-03-08
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
相关资源
相似解决方案