转换对象为JSON<br>
支持的对象：<br>
String: 转换为相应的对象<br>
Array Collection：转换为JSONArray<br>
Bean对象：转为JSONObject

@param obj 对象
@return JSON
506536
public static JSON parse(Object obj) {
		if (null == obj) {
			return null;
		}

		JSON json = null;
		if (obj instanceof JSON) {
			json = (JSON) obj;
		} else if (obj instanceof String) {
			String jsonStr = ((String) obj).trim();
			if (jsonStr.startsWith("[")) {
				json = parseArray(jsonStr);
			} else {
				json = parseObj(jsonStr);
			}
		} else if (obj instanceof Collection || obj.getClass().isArray()) {// 列表
			json = new JSONArray(obj);
		} else {// 对象
			json = new JSONObject(obj);
		}

		return json;
	}
1069013
public JSONObject toJson() throws IOException {
    String base64 = new Zip().zip(getDirectory());
    Map<String, String> map = ImmutableMap.of(
      "className", this.getClass().getName(),
      BASE64_JSON_KEY, base64);
    
    return new JSONObject(map);
  }
1060715
public static <T> byte[] serialize(T obj) {
		if (null == obj || false == (obj instanceof Serializable)) {
			return null;
		}

		FastByteArrayOutputStream byteOut = new FastByteArrayOutputStream();
		ObjectOutputStream oos = null;
		try {
			oos = new ObjectOutputStream(byteOut);
			oos.writeObject(obj);
			oos.flush();
		} catch (Exception e) {
			throw new UtilException(e);
		} finally {
			IoUtil.close(oos);
		}
		return byteOut.toByteArray();
	}
355114
public String objectToString(Object obj)
    {
        String string = super.objectToString(obj);
        string = Base64.encode(string);
        return string;
    }
28927
public static String serialise(Object object) {
        Gson gson = getBuilder().create();
        return gson.toJson(object);
    }
579952
public static String toJson(Object object) {
        Objects.requireNonNull(object, Required.OBJECT.toString());
        
        String json = null;
        try {
            json = mapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            LOG.error("Failed to convert object to json",  e);
        }
        
        return json;
    }
519334
public static String json(Object obj, boolean writeClass,
                              Converter<Object, Map<String, Object>> mc) throws IOException {
        if (obj == null)
            return NULL;
        StringWriter sw = new StringWriter();
        try {
            json(obj, sw, writeClass, mc);
            return sw.getBuffer().toString();
        } finally {
            sw.close();
        }
    }
1261585
public static byte[] serialize(Object obj) {
        try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos)) {
            oos.writeObject(obj);
            return bos.toByteArray();
        } 
        catch (IOException ex) {
            throw new UncheckedIOException(ex);
        }
    }
229825
public JSONObject toJson() {
        JSONObject ret = new JSONObject();
        JSONArray columns = new JSONArray(Arrays.asList(new String[]{"time"}));
        for (String f : this.columns) {
            columns.put(f);
        }
        ret.put(KEY_COLUMNS, columns);

        JSONArray data = new JSONArray();
        ret.put(KEY_ROWS, data);
        for (Long ts : rows.keySet()) {
            JSONArray row = new JSONArray();
            row.put(ts);
            Map<String, Object> temp = rows.get(ts);
            for (String f : this.columns) {
                Object val = temp.get(f);
                row.put(val != null ? val : JSONObject.NULL);
            }
            data.put(row);
        }

        return ret;
    }
698919
public JSONObject toJSON() {
        JSONObject ret = new JSONObject();
        ret.put("url", url);
        if (env != null) {
            ret.put("env", env);
        }
        return ret;
    }
1107299
public static String serialize(Object obj) throws SerializationException {
		try {
			if (obj != null) {
				return mapper.writeValueAsString(obj);
			} else {
				return null;
			}
		} catch (Exception e) {
			logger.error("SerializationException {}", e.getMessage());
			throw new SerializationException(e.getMessage());
		}
	}
609917
public static String serialize(Object obj) throws ApiException {
        try {
            if (obj != null)
                    if (obj instanceof String) {
                        // This assumes that we receive json as a string
                        return (String) obj;
                } else {
                        return JsonUtil.getJsonMapper().writeValueAsString(obj);
                }
            else
                return null;
        }
        catch (Exception e) {
            throw new ApiException(500, e.getMessage());
        }
    }
576007
public static Object[] asArray(Object obj) {

        if (obj == null) {

            return new Object[] {}; // 返回空数组

        } else if (obj.getClass().isArray()) {

            Class<?> componentType = obj.getClass().getComponentType();

            // 转换元素为基本类型的数组
            if (componentType.isPrimitive()) {

                final int length = Array.getLength(obj);

                Object[] array = new Object[length];

                for (int index = 0; index < length; index++) {
                    array[index] = Array.get(obj, index);
                }

                return array;
            }

            // 数组直接返回
            return (Object[]) obj;

        } else {

            return new Object[] { obj }; // 其他类型, 返回包含单个对象的数组
        }
    }
1236231
public JSONBuilder toJSON(JSONBuilder jb) {
        return jb.append('{').serialize("columns", columns).append(',').serialize("rows", rows).append('}');
    }
610389
public static String serialize(Object[] objs)
    {
        StringBuffer buff = new StringBuffer();
        for(int i = 0; i < objs.length; i++)
        {
            if(objs[i] != null)
            {
                buff.append(objs[i].toString());
                if(i != objs.length-1)
                    buff.append(",");
            }
        }
        return buff.toString();
    }
307625
public static SanitizedContent serializeObject(Gson gson, Object obj) {
    return ordainJson(gson.toJson(obj));
  }
825616
@Override
    public String serialize(Object obj) throws JsonMarshallingException {
        try {
            return serializeChecked(obj);
        } catch (Exception e) {
            throw new JsonMarshallingException(e);
        }
    }