Serialize an object to a json string. Use when object is expected to be json serializable.

@param value The object to serialize.

@return The serialized object.

@see #asPrettyString(Object)
969179
public static String asPrettyStringUnchecked(final Object value) {
    try {
      return asPrettyString(value);
    } catch (JsonProcessingException e) {
      throw new RuntimeException(e);
    }
  }
989944
protected String formatToString(Object value) {
        if (value == null) return null;
        if (value instanceof CharSequence) {
            return new StringBuilder().append('\'').append(value.toString().replace("'", "\\'")).append('\'').toString();
        } else if (!(value instanceof Number) && !(value instanceof java.util.Date)
            && !value.getClass().getName().startsWith("java.sql.") && !value.getClass().getName().startsWith("java.time.")) {
            return new StringBuilder().append('\'').append(jsonConvert.convertTo(value).replace("'", "\\'")).append('\'').toString();
        }
        return String.valueOf(value);
    }
1105397
@Override
    public String convertTo(final Object value) {
        if (value == null) return "null";
        return convertTo(value.getClass(), value);
    }
155517
private JsonElement convertValue(String value, JsonObject dataType) {
    if (dataType == null || !dataType.has(TYPE)) {
      return new JsonPrimitive(value);
    }

    String type = dataType.get(TYPE).getAsString().toUpperCase();
    ValueType valueType = ValueType.valueOf(type);
    return valueType.convert(value);
  }
808012
@Override
	public Long serialize(Date value) {
		if (value != null) {
			return value.getTime();
		}
		return null;
	}
423087
public static String toJson(Object value) throws JsonProcessingException {
		if (value == null)
			return null;
		return _mapper.writeValueAsString(value);
	}
308201
public static String toJson(Object value) {
        if (value instanceof String) {
            return '"' + (String) value + '"';
        } else if (value instanceof Collection) {
            return "[" + toJsonCollection((Collection) value) + "]";
        } else {
            throw new IllegalArgumentException("Unable to convert " + value + " to JSON");
        }
    }
107709
private static String getJsonValueAsNumberString(JsonValue value) {
        return (value != null && value.getValueType() == ValueType.NUMBER) ? value.toString() : null;
    }
965949
def serialize(self, value, **kwargs):
        
        if self._serialize is not None:
            return self._serialize(value, **kwargs)
        else:
            return value
1143661
public JsonWriter valueLiteral(CharSequence value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writer.write(value.toString());
        }
        return this;
    }
740828
public final JsonElement toJsonTree(T value) {
    try {
      JsonTreeWriter jsonWriter = new JsonTreeWriter();
      write(jsonWriter, value);
      return jsonWriter.get();
    } catch (IOException e) {
      throw new JsonIOException(e);
    }
  }
562370
private String encode(Object value) {
    return BaseEncoding.base16().encode(valueSerializer.encode(value));
  }
765070
public static String objectToString(Object value) {
    if (value == null) {
      return null;
    }
    if (value instanceof String) {
      return (String)value;
    }
    if (value instanceof String[]) {
      return StringUtils.join(encodeString((String[])value), ARRAY_DELIMITER);
    }
    else if (value instanceof Integer) {
      return Integer.toString((Integer)value);
    }
    else if (value instanceof Long) {
      return Long.toString((Long)value);
    }
    else if (value instanceof Double) {
      return Double.toString((Double)value);
    }
    else if (value instanceof Boolean) {
      return Boolean.toString((Boolean)value);
    }
    else if (value instanceof Map) {
      Map<?, ?> map = (Map<?, ?>)value;
      StringBuilder stringValue = new StringBuilder();
      Map.Entry<?, ?>[] entries = Iterators.toArray(map.entrySet().iterator(), Map.Entry.class);
      for (int i = 0; i < entries.length; i++) {
        Map.Entry<?, ?> entry = entries[i];
        String entryKey = encodeString(Objects.toString(entry.getKey(), ""));
        String entryValue = encodeString(Objects.toString(entry.getValue(), ""));
        stringValue.append(entryKey).append(KEY_VALUE_DELIMITER).append(entryValue);
        if (i < entries.length - 1) {
          stringValue.append(ARRAY_DELIMITER);
        }
      }
      return stringValue.toString();
    }
    throw new IllegalArgumentException("Unsupported type: " + value.getClass().getName());
  }
835937
public static String typeString(Object value) {
        return null == value || Primitive.NULL == value
            ? "null"
            : value instanceof Primitive
                ? ((Primitive) value).getType().getSimpleName()
                : typeString(value.getClass());
    }
418909
public static byte[] asBytesUnchecked(final Object value) {
    try {
      return OBJECT_MAPPER.writeValueAsBytes(value);
    } catch (JsonProcessingException e) {
      throw new RuntimeException(e);
    }
  }
852862
protected function serialize($value)
    {
        $jsonOptions = JSON_PRETTY_PRINT;
        if (defined('JSON_UNESCAPED_SLASHES')) {
            $jsonOptions |= JSON_UNESCAPED_SLASHES;
        }
        $type = gettype($value);
        $result = null;
        switch ($type) {
            case 'array':
                $result = json_encode($value, $jsonOptions);
                break;

            case 'boolean':
                $result = $value ? 'true' : 'false';
                break;

            case 'NULL':
                $result = 'null';
                break;

            case 'integer':
            case 'double':
                $result = (string)$value;
                break;

            case 'string':
                $enquote = false;
                switch ($value) {
                    case 'true':
                    case 'false':
                    case 'null':
                        $enquote = true;
                        break;

                    default:
                        if (preg_match('/^-?\d+(\.\d*)?$/', $value)) {
                            $enquote = true;
                        }
                        break;
                }
                $result = $enquote ? "\"$value\"" : $value;
                break;
        }
        if (!isset($result)) {
            throw new Exception("Unable to represent variable of type '$type'");
        }

        return $result;
    }
96035
public static String encodeString(final String value) {
    StringBuilder out = new StringBuilder();
    encodeString( value, out );
    return out.toString();
  }