Here you can find the source of toJSON(T obj)
public static <T> String toJSON(T obj)
//package com.java2s; //License from project: Apache License import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static <T> String toJSON(T obj) { String json = null;/*www . j av a 2s . c o m*/ try { ObjectMapper mapper = new ObjectMapper(); json = mapper.writeValueAsString(obj); } catch (Exception e) { e.printStackTrace(); } return json; } }