将对象以JSON格式输出

@param convert 指定的JsonConvert
@param obj     输出对象
512307
public void finishJson(final JsonConvert convert, final Object obj) {
        this.contentType = this.jsonContentType;
        if (this.recycleListener != null) this.output = obj;
        finish(convert.convertTo(getBodyBufferSupplier(), obj));
    }
989624
public void finishJson(final Object obj) {
        this.contentType = this.jsonContentType;
        if (this.recycleListener != null) this.output = obj;
        finish(request.getJsonConvert().convertTo(getBodyBufferSupplier(), obj));
    }
501978
public Routing routingFromJSON(Model mo, JSONObject o) throws JSONConverterException {

        String type = requiredString(o, "type");
        RoutingConverter<? extends Routing> c = json2java.get(type);
        if (c == null) {
            throw new JSONConverterException("No converter available for a routing of type '" + type + "'");
        }
        return c.fromJSON(mo, o);
    }
413850
public static <P extends ParaObject> String toJSON(P obj) {
		if (obj == null) {
			return "{}";
		}
		try {
			return getJsonWriter().writeValueAsString(obj);
		} catch (Exception e) {
			logger.error(null, e);
		}
		return "{}";
	}
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;
	}
1092536
@SuppressWarnings("unchecked")
    public void finish(final Convert convert, final Object obj) {
        finish(convert, (Type) null, obj);
    }
520121
@SuppressWarnings("unchecked")
   @Override
   public Object convert(Object source)
   {
      Object value = source;
      for (Converter<Object, Object> converter : converters)
      {
         if (converter != null)
         {
            value = converter.convert(value);
         }
      }
      return value;
   }
336947
public static String convertObjectToString(Object obj)
    {
        try {
            ByteArrayOutputStream writer = new ByteArrayOutputStream();
            ObjectOutputStream outStream = new ObjectOutputStream(writer);
            outStream.writeObject(obj);
            outStream.flush();
            writer.flush();
            String string = writer.toString(Constant.OBJECT_ENCODING);//Constants.STRING_ENCODING);
            writer.close();
            outStream.close();
            return string;
        } catch (IOException ex)    {
            ex.printStackTrace();   // Never
        }
        return null;
    }
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;
    }
408833
public static JsonNode toJson(Object obj, ClassLoader classLoader) {
        return SerializationUtils.toJson(obj, classLoader);
    }
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());
        }
    }
900346
public String toJson(Object obj, boolean ignoreNull) {
        if (obj == null) {
            return null;
        }
        if (obj instanceof String) {
            return (String) obj;
        }
        try {
            ObjectMapper mapper;
            if (ignoreNull) {
                mapper = MAPPER_IGNORE_NULL;
            } else {
                mapper = MAPPER;
            }
            return mapper.writeValueAsString(obj);
        } catch (Exception e) {
            log.error("序列化失败，失败原因：", e);
            return "";
        }
    }
134876
@Bean
	@ConditionalOnMissingBean(name = "busJsonConverter")
	@StreamMessageConverter
	public AbstractMessageConverter busJsonConverter(
			@Autowired(required = false) ObjectMapper objectMapper) {
		return new BusJacksonMessageConverter(objectMapper);
	}
1241369
function convert(object) {
  return Object.keys(object).reduce((newObj, originalKey) => {
    let originalValue = object[originalKey]
    if (isString(originalValue)) {
      // you're welcome to later code 😺
      originalValue = originalValue.trim()
    }

    // Some properties should never be transformed
    if (includes(propsToIgnore, originalKey)) {
      newObj[originalKey] = originalValue
      return newObj
    }

    const {key, value} = convertProperty(originalKey, originalValue)
    newObj[key] = value
    return newObj
  }, Array.isArray(object) ? [] : {})
}
6564
public static String toJSONString(final Object obj) {
        try {
            return mapper.writeValueAsString(obj);
        } catch (final JsonProcessingException e) {
            logger.error("Cannot to JSON string", e);
        }
        return null;
    }
587945
@SuppressWarnings("unchecked")
    public void finish(final Convert convert, final Type type, final Object obj) {
        if (obj == null) {
            finish("null");
        } else if (obj instanceof CompletableFuture) {
            ((CompletableFuture) obj).whenComplete((v, e) -> {
                if (e != null) {
                    context.getLogger().log(Level.WARNING, "Servlet occur, force to close channel. request = " + request + ", result is CompletableFuture", (Throwable) e);
                    finish(500, null);
                    return;
                }
                finish(convert, type, v);
            });
        } else if (obj instanceof CharSequence) {
            finish((String) obj.toString());
        } else if (obj instanceof byte[]) {
            finish((byte[]) obj);
        }
403065
@Nonnull
  public SoyValueProvider convert(@Nullable Object obj) {
    SoyValueProvider convertedPrimitive = convertCheap(obj);
    if (convertedPrimitive != null) {
      return convertedPrimitive;
    }
    return convertNonPrimitive(obj);
  }