• Narrows an array of type T to a JsonArray following a deep, brute-force conversion of the array's data to only consist of JSON-compatible values by performing a basic JSON clone on the array. This is preferable to using the weaker coerceJsonArray(array) to type-narrow an arbitrary array to a JsonArray when the array's source is unknown, but it comes with the increased overhead of performing the deep JSON clone to ensure runtime type safety. The use of JSON cloning guarantees type safety by omitting non-JSON-compatible elements from the resulting JSON data structure. Non-JSON entries will be converted to nulls. Use coerceJsonArray(array) when the value object can be guaranteed to be JSON-compatible and only needs type coercion.

    Type Parameters

    • T

    Parameters

    • value: T[]

      The array to convert.

    Returns JsonArray

    JsonCloneError If the array values contain circular references.

  • Narrows an array of type T to a JsonArray following a deep, brute-force conversion of the array's data to only consist of JSON-compatible values by performing a basic JSON clone on the array. This is preferable to using the weaker coerceJsonArray(array) to type-narrow an arbitrary array to a JsonArray when the array's source is unknown, but it comes with the increased overhead of performing the deep JSON clone to ensure runtime type safety. The use of JSON cloning guarantees type safety by omitting non-JSON-compatible elements from the resulting JSON data structure. Non-JSON entries will be converted to nulls. Use coerceJsonArray(array) when the value object can be guaranteed to be JSON-compatible and only needs type coercion.

    Type Parameters

    • T

    Parameters

    Returns Optional<JsonArray>

    JsonCloneError If the array values contain circular references.

  • Narrows an object of type T to a JsonMap following a deep, brute-force conversion of the object's data to only consist of JSON-compatible values by performing a basic JSON clone on the object. This is preferable to using the weaker coerceJsonMap(object) to type-narrow an arbitrary array to a JsonMap when the object's source is unknown, but it comes with the increased overhead of performing the deep JSON clone to ensure runtime type safety. The use of JSON cloning guarantees type safety by omitting non-JSON-compatible elements from the resulting JSON data structure. Non-JSON entries will be converted to nulls. Use coerceJsonArray(array) when the value object can be guaranteed to be JSON-compatible and only needs type coercion.

    Type Parameters

    • T

    Parameters

    • value: Optional<T[]>

      The array to convert.

    • defaultValue: JsonArray

      The default to return if the value was undefined or of the incorrect type.

    Returns JsonArray

    JsonCloneError If the array values contain circular references.