Package cc.ekblad.toml

Types

TomlDecoder
Link copied to clipboard
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.

TomlException
Link copied to clipboard
sealed class TomlException : RuntimeException

Base class of all exceptions that might be thrown during TOML processing.

TomlValue
Link copied to clipboard
sealed class TomlValue

Kotlin representation of a TOML value. A full TOML document is always represented as a TomlValue.Map.

Functions

decode
Link copied to clipboard
inline fun <T : Any> TomlValue.decode(): T

Decodes the receiver TOML value to the type indicated by type parameter T using the default TOML decoder. If the value can't be decoded into the target type, a TomlException.DecodingError is thrown.

inline fun <T : Any> TomlValue.decode(decoder: TomlDecoder): T

Decodes the receiver TOML value into a value of type T, using the given custom decoder.

fun <T : Any> TomlValue.decode(type: KType): T

Decodes the receiver TOML value into a value of the type corresponding to the given KType. T and type should correspond to the same type, or the behavior of decode is undefined.

fun <T : Any> TomlValue.decode(decoder: TomlDecoder, type: KType): T

Decodes the receiver TOML value into a value of the type corresponding to the given KType, using the given custom decoder. T and type should correspond to the same type, or the behavior of decode is undefined.

get
Link copied to clipboard
inline operator fun <T : Any> TomlValue.get(vararg path: String): T?

Look up the value(s) at the given path in the receiver TOML structure, then decode them into the type given by the type parameter T. If decoding is not possible, a TomlException.DecodingError is thrown. If there is no value at the given path, null is returned.

inline fun <T : Any> TomlValue.get(decoder: TomlDecoder, vararg path: String): T?

Look up the value(s) at the given path in the receiver TOML structure, then decode them into the type given by T using the given custom TOML decoder.

fun <T> TomlValue.get(targetType: KType, path: List<String>): T?

Look up the value(s) at the given path in the receiver TOML structure, then decode them into the type given by targetKType. targetKType and T should correspond to the same type, or the behavior of get is undefined.

fun <T> TomlValue.get(decoder: TomlDecoder, targetType: KType, path: List<String>): T?

Look up the value(s) at the given path in the receiver TOML structure, then decode them into the type given by targetKType using the given custom TOML decoder. targetKType and T should correspond to the same type, or the behavior of get is undefined.

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.