SimplePrimitive

class SimplePrimitive(val value: Any?) : KpaPrimitive(source)

Trivial implementation of KpaPrimitive wrapping a plain value.

Intended as a reference implementation for testing or for consumers that do not use a specific JSON library.

Parameters

value

The wrapped value (can be any type, including null).

Constructors

Link copied to clipboard
constructor(value: Any?)

Properties

Link copied to clipboard
open override val booleanOrNull: Boolean?

The boolean value if isBoolean; null otherwise.

Link copied to clipboard
open override val doubleOrNull: Double?

The numeric value as Double if isNumber; null otherwise.

Link copied to clipboard
open override val isBoolean: Boolean

true if value is a Boolean.

Link copied to clipboard
open override val isNull: Boolean

true if value is null.

Link copied to clipboard
open override val isNumber: Boolean

true if value is a Number (covers Int, Long, Float, Double).

Link copied to clipboard
open override val isString: Boolean

true if value is a String.

Link copied to clipboard
open override val longOrNull: Long?

The numeric value as Long if value is Long or Int; null for all other types.

Link copied to clipboard
open override val stringOrNull: String?

The string value if isString; null otherwise.

Link copied to clipboard
val value: Any?

Functions

Link copied to clipboard
open override fun renderedString(): String

The string value for strings; "null" for null; value.toString() for all other types.

Link copied to clipboard
inline fun <B : Any> KpaElement.requireBacking(libraryName: String): B

Unwraps this KpaElement to its native backing value of type B, or throws if this element is not a BackedKpaElement whose backing is of type B.