Here you can find the source of toJson(List
public static <T> String toJson(List<T> list)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.Map; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static <T> String toJson(List<T> list) { try {/*from w w w . j av a 2 s. c o m*/ return new ObjectMapper().writeValueAsString(list); } catch (JsonProcessingException e) { e.printStackTrace(); } return ""; } public static <K, V> String toJson(Map<K, V> map) { try { return new ObjectMapper().writeValueAsString(map); } catch (JsonProcessingException e) { e.printStackTrace(); } return ""; } }