Here you can find the source of toJSON(T valueType)
public static <T> String toJSON(T valueType)
//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; import com.fasterxml.jackson.databind.SerializationFeature; public class Main { private static final ObjectMapper objectMapper = new ObjectMapper(); public static <T> String toJSON(T valueType) { objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String json = "Problem serializing " + valueType.getClass(); try {/*from w w w . j av a 2s . c o m*/ json = objectMapper.writeValueAsString(valueType); } catch (JsonProcessingException e) { e.printStackTrace(); } return json; } }