code: private static Object toJson(Object obj, JsonBuilderFactory factory) {
  		if (obj instanceof JsonObject) {
  			return ((JsonObject)obj).toJson(factory.createJsonBuilder());
  		} else if (obj.getClass().isArray()) {
  			List<Object> r = new ArrayList<>();
  			int len = Array.getLength(obj);
  			for (int i = 0; i < len; ++i) {
  				Object ao = Array.get(obj, i);
  				r.add(toJson(ao, factory));
  			}
  			return r;
  		} else if (obj instanceof Collection) {
  			Collection<?> coll = (Collection<?>)obj;
  			List<Object> r = new ArrayList<>();
  			for (Object ao : coll) {
  				r.add(toJson(ao, factory));
  			}
  			return r;
  		} else if (obj instanceof Map) {
  			Map<?, ?> m = (Map<?, ?>)obj;
  			Map<String, Object> r = new LinkedHashMap<>();
  			for (Map.Entry<?, ?> e : m.entrySet()) {
  				String key = toJson(e.getKey(), factory).toString();
  				Object value = toJson(e.getValue(), factory);
  				r.put(key, value);
  			}
  			return r;
  		}
  		return obj;
  	}
docs: Converts an object to a JSON object
  @param obj the object to convert
  @param factory a factory used to create JSON builders
  @return the JSON object