Function coerceJsonMap

  • Narrows an object of type T to a JsonMap using a shallow type-compatibility check. Use this when the source of the object is known to be JSON-compatible and you want simple type coercion to a JsonMap. Use toJsonMap instead when the value object cannot be guaranteed to be JSON-compatible and you want an assurance of runtime type safety. This is a shortcut for writing asJsonMap(coerceAnyJson(value)).

    Type Parameters

    • T extends object

    Parameters

    Returns Optional<JsonMap>

  • Narrows an object of type T to a JsonMap using a shallow type-compatibility check. Use this when the source of the object is known to be JSON-compatible and you want simple type coercion to a JsonMap. Use toJsonMap instead when the value object cannot be guaranteed to be JSON-compatible and you want an assurance of runtime type safety. This is a shortcut for writing asJsonMap(coerceAnyJson(value)) ?? defaultValue.

    Type Parameters

    • T extends object

    Parameters

    • value: Nullable<T>

      The object to coerce.

    • defaultValue: JsonMap

      The default to return if value was not defined.

    Returns JsonMap