object to json

@param <T> T t
@param t   参数类型
@return string
546950
public static <T> String toJson(T t) {
        if (Objects.isNull(t)) {
            log.warn("t is blank. ");
            return "";
        }
        try {
            return OBJECT_MAPPER.writeValueAsString(t);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return "";
        }
    }
351260
public static String toJson(Object obj) {
		try {
			return objectMapper.writeValueAsString(obj);
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	}
600820
public static String toJson(Object obj) {
		ObjectMapper mapper = new ObjectMapper();
		try {
			return mapper.writeValueAsString(obj);
		} catch (IOException e) {
			JK.throww(e);
			return null;
		}
	}
776193
def to_json(self, *args, **kwargs):
        """"""
        return json.dumps(self.serialize(), *args, **kwargs)
53573
public static <T extends TBase> String serializeJson(T obj) throws TException {
		// Tried having a static final serializer, but it doesn't seem to be thread safe
		return new TSerializer(new TJSONProtocol.Factory()).toString(obj, THRIFT_CHARSET);
	}
367577
public static String toJSONString(Object o) {
    try {
      return objectMapper.writer().without(SerializationFeature.INDENT_OUTPUT).writeValueAsString(o);
    } catch (JsonProcessingException e) {
      throw new RuntimeException(e);
    }
  }
220889
public static <D> String toJsonString(D dataObject) {
        try {
            return jsonMapper.writeValueAsString(dataObject);
        } catch (Exception e) {
            return JMExceptionManager.handleExceptionAndReturnNull(log, e,
                    "toJsonString", dataObject);
        }
    }
1309309
public String toJson(JsonElement jsonElement) {
    StringWriter writer = new StringWriter();
    toJson(jsonElement, writer);
    return writer.toString();
  }
1286225
public String toJson() {
        Map<String, Object> data = toMap();
        return SerializationUtils.toJsonString(data);
    }
276519
public static final String serializeToString(final Object object) {
    if (object == null)
      throw new IllegalArgumentException("Object was null");
    try {
      return jsonMapper.writeValueAsString(object);
    } catch (JsonProcessingException e) {
      throw new JSONException(e);
    }
  }
104062
public String toJsonString() {
	JSONArray jsonArray = new JSONArray();
	jsonArray.put(data);
	return jsonArray.toString();
    }
567714
public String serialize(Object object) {
		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("Serializing object to Json");
		}
		XStream xstream = new XStream(new JettisonMappedXmlDriver());
		String json = xstream.toXML(object);
		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("Object serialized well");
		}
		return json;
	}
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;
    }
1187338
public String toJSONString() {
        if (context.isPretty()) {
            return JSON.toJSONStringWithDateFormat(this, Constant.DATE_SERIALIZE_FORMAT, SerializerFeature.PrettyFormat);
        } else {
            return JSONObject.toJSONStringWithDateFormat(this, Constant.DATE_SERIALIZE_FORMAT);
        }
    }
247405
public static String toPrettyJson(Object o) {
		try {
			return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(o);
		} catch (JsonProcessingException e) {
			LoggerFactory
			        .getLogger(Serializer.class)
			        .error("Could not serialize the object. This will be ignored and the error will be written instead. Object was {}",
			                o, e);
			return "\"" + e.getMessage() + "\"";
		}
	}
1243234
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;
	}
939786
public static String toJSON(TBase thriftObject) {
		try {
			return simpleJSONserializer.toString(thriftObject);
		} catch(TException e) {
			return e.getMessage();
		}
	}