extension

inline fun <T> ProblemBuilder.extension(name: String, value: T)(source)

Adds one extension member holding an arbitrary @Serializable value, with the serializer resolved from T.

Samples

problem {
        type = "https://example.com/probs/out-of-credit"
        status = 403
        title = "You do not have enough credit."
        detail = "Your current balance is 30, but that costs 50."

        // Serialized with kotlinx and added as one extension member named "account".
        extension("account", Account(id = "12345", balance = 30))
    }

fun <T> Problem.extension(name: String, deserializer: DeserializationStrategy<T>, json: Json = ProblemJson): T?(source)

Decodes a single extension member, or returns null when it is absent.

Absence and a present-but-undecodable member are different cases. A member of the wrong shape throws; it does not return null. Read it through Problem.extensions and the lenient accessors, stringOrNull and friends, to follow §3's "ignore it like an absent member" rule.


inline fun <T> Problem.extension(name: String, json: Json = ProblemJson): T?(source)

Decodes a single extension member with the deserializer resolved from T, or returns null when the member is absent.