TomlDecoder

class TomlDecoder

Describes how TOML values are to be decoded into Kotlin model types. decode, get, etc. all accept an optional TomlDecoder to customize their behavior. If no custom decoder is given, TomlDecoder.default is used.

Types

Companion
Link copied to clipboard
object Companion

Functions

pass
Link copied to clipboard
fun pass(): Nothing

Called by a decoder function to indicate that it can't decode the given TOML into its target type and that the next decoder function for the target type should be given a chance instead.

with
Link copied to clipboard
fun with(vararg decoderFunctions: Pair<KClass<*>, TomlDecoder.(targetType: KType, tomlValue: TomlValue) -> Any?>): TomlDecoder

Returns a copy of the target TOML decoder, extended with zero or more additional custom decoder functions. A custom decoder function is a function from a TomlValue and a KType representing that a target type to that target type. Custom decoder functions are associated with a KClass representing that target type.

inline fun <T : TomlValue, R> with(crossinline decoderFunction: TomlDecoder.(T) -> R): TomlDecoder

Returns a copy of the receiver TOML decoder extended with a single custom decoder function, without having to manually specify its target type.

inline fun <T : TomlValue, R> with(crossinline decoderFunction: TomlDecoder.(targetType: KType, T) -> R): TomlDecoder

Returns a copy of the receiver TOML decoder extended with a single custom decoder function, without having to manually specify its target type. The custom decoder function may make decoding decisions based on the KType corresponding to the decoder target type.

Extensions

withMapping
Link copied to clipboard
inline fun <T : Any> TomlDecoder.withMapping(vararg mapping: Pair<String, String>): TomlDecoder
fun <T : Any> TomlDecoder.withMapping(kClass: KClass<T>, vararg mapping: Pair<String, String>): TomlDecoder

Returns a copy of the receiver TOML decoder, extended with a custom property mapping for the type T.