Here you can find the source of obj2Json(Object obj)
public static String obj2Json(Object obj)
//package com.java2s; //License from project: Apache License import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; public class Main { public static String obj2Json(Object obj) { try {/*from ww w . j av a2 s .co m*/ ObjectMapper objectMapper = new ObjectMapper(); ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter(); return ow.writeValueAsString(obj); } catch (Exception e) { e.printStackTrace(); return null; } } }