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
Using gson it is much simpler. Use following code snippet:
// create a new Gson instance
Gson gson = new Gson();
// convert your list to json
String jsonCartList = gson.toJson(cartList);
// print your generated json
System.out.println("jsonCartList: " + jsonCartList);
// Converts JSON string into a List of Product object
Type type = new TypeToken>(){}.getType();
List prodList = gson.fromJson(jsonCartList, type);
// print your List
System.out.println("prodList: " + prodList);