Here you can find the source of toJson(Object value)
public static final String toJson(Object value)
//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.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class Main { private static final ObjectMapper mapper = new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) .setSerializationInclusion(JsonInclude.Include.NON_NULL) .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); public static final String toJson(Object value) { try {/*from ww w. ja v a 2s .c om*/ return mapper.writeValueAsString(value); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } }