code: private static Object toJson(Object obj, JsonBuilderFactory factory) {
  		if (obj instanceof JsonObject) {
  			return toJson((JsonObject)obj, factory);
  		} else if (obj instanceof Number) {
  			return toJson((Number)obj);
  		} else if (obj instanceof Boolean) {
  			return toJson(((Boolean)obj).booleanValue());
  		} else if (obj.getClass().isArray()) {
  			StringBuilder r = new StringBuilder();
  			int len = Array.getLength(obj);
  			for (int i = 0; i < len; ++i) {
  				Object ao = Array.get(obj, i);
  				if (r.length() > 0) {
  					r.append(",");
  				}
  				r.append(toJson(ao, factory));
  			}
  			return "[" + r.toString() + "]";
  		} else if (obj instanceof Collection) {
  			Collection<?> coll = (Collection<?>)obj;
  			StringBuilder r = new StringBuilder();
  			for (Object ao : coll) {
  				if (r.length() > 0) {
  					r.append(",");
  				}
  				r.append(toJson(ao, factory));
  			}
  			return "[" + r.toString() + "]";
  		} else if (obj instanceof Map) {
  			Map<?, ?> m = (Map<?, ?>)obj;
  			StringBuilder r = new StringBuilder();
  			for (Map.Entry<?, ?> e : m.entrySet()) {
  				if (r.length() > 0) {
  					r.append(",");
  				}
  				r.append(toJson(e.getKey(), factory));
  				r.append(":");
  				r.append(toJson(e.getValue(), factory));
  			}
  			return "{" + r.toString() + "}";
  		}
  		return toJson(String.valueOf(obj));
  	}
docs: Converts an object to a JSON object. The given object can be a
  {@link JsonObject}, a primitive, a string, or an array. Converts
  the object to a string via {@link Object#toString()} if its type
  is unknown and then converts this string to JSON.
  @param obj the object to convert
  @param factory a factory used to create JSON builders
  @return the JSON object