wrap

open fun wrap(@Nullable value: String): JsonValue

Wraps a String as a JsonValue.

Return

The JsonValue object.

Parameters

value

The value as a string.


open fun wrap(value: Char): JsonValue

Wraps a char as a JsonValue.

Return

The JsonValue object.

Parameters

value

The value as a char.


open fun wrap(value: Int): JsonValue

Wraps an int as a JsonValue.

Return

The JsonValue object.

Parameters

value

The value as an int.


open fun wrap(value: Long): JsonValue

Wraps a long as a JsonValue.

Return

The JsonValue object.

Parameters

value

The value as a long.


open fun wrap(value: Boolean): JsonValue

Wraps a boolean as a JsonValue.

Return

The JsonValue object.

Parameters

value

The value as a boolean.


open fun wrap(value: Double): JsonValue

Wraps a double as a JsonValue.

Return

The JsonValue object.

Parameters

value

The value as a double.


Wraps a JsonSerializable object as a JsonValue.

Return

The JsonValue object.

Parameters

value

The value as a JsonSerializable object.


open fun wrap(@Nullable object: Any, @NonNull defaultValue: JsonValue): JsonValue

Wraps any valid object into a JsonValue. If the object is unable to be wrapped, the default value will be returned. See wrap for rules on object wrapping.

Return

The object wrapped in a JsonValue or the default value if the object is unable to be wrapped.

Parameters

object

The object to wrap.

defaultValue

The default value if the object is unable to be wrapped.


open fun wrap(@Nullable object: Any): JsonValue

Wraps any valid object into a JsonValue.

Objects will be wrapped with the following rules:

  • JSONObject.NULL or null will result in NULL.
  • Collections, arrays, JSONArray values will be wrapped into a JsonList
  • Maps with String keys will be wrapped into a JsonMap.
  • Strings, primitive wrapper objects, JsonMaps, and JsonLists will be wrapped directly into a JsonValue
  • Objects that implement JsonSerializable will return toJsonValue or NULL.
  • JsonValues will be unmodified.

Return

The object wrapped in a JsonValue.

Parameters

object

The object to wrap.

Throws

If the object is not a supported type or contains an unsupported type.