How to convert list data into json in java

前端 未结 7 1187
天涯浪人
天涯浪人 2020-11-30 06:57

I have a function which is returning Data as List in java class. Now as per my need, I have to convert it into Json Format.

Below is my fun

7条回答
  •  迷失自我
    2020-11-30 07:10

    Try these simple steps:

    ObjectMapper mapper = new ObjectMapper();
    String newJsonData = mapper.writeValueAsString(cartList);
    return newJsonData;
    ObjectMapper() is com.fasterxml.jackson.databind.ObjectMapper.ObjectMapper();
    

提交回复
热议问题