Here you can find the source of toJSON(Object obj)
public static String toJSON(Object obj) throws JsonProcessingException
//package com.java2s; //License from project: Open Source License import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static String toJSON(Object obj) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsString(obj); }/* w w w .jav a 2 s. c om*/ }