Here you can find the source of convertToJson(Object myObject)
public static String convertToJson(Object myObject)
//package com.java2s; //License from project: LGPL import java.util.Map; public class Main { public static String convertToJson(Object myObject) { if (myObject instanceof Map<?, ?>) { final Map<?, ?> map = (Map<?, ?>) myObject; final StringBuilder sb = new StringBuilder("{"); boolean first = true; for (final Map.Entry<?, ?> entry : map.entrySet()) { if (first) { first = false;// ww w . j a va2 s . c o m } else { sb.append(","); } sb.append("\n\t'").append(entry.getKey()).append("':'").append(entry.getValue()).append("'"); } if (!first) { sb.append("\n"); } sb.append("}"); System.out.println(sb.toString()); return sb.toString(); } else { System.out.println(myObject); } return ""; } }