Toml

sealed class Toml : StringFormat(source)

The main entry point to use TOML.

Programmer could simply use Default instance or customize configuration by using the factory function with the same name.

Basic usage:

@Serializable
data class User(
val name: String,
val account: Account? // Nullable property.
)

@Serializable
data class Account(
val username: String,
val password: String
)

val user = User("Peanuuutz", Account("Peanuuutz", "123456"))
// With [Default] instance.
// Either is OK, but to explicitly pass a serializer is faster.
val tomlString = Toml.encodeToString(User.serializer(), user)
val tomlString = Toml.encodeToString<User>(user)
// Print it.
println(tomlString)
/*
name = "Peanuuutz"

[account]
username = "Peanuuutz"
password = "123456"
*/

// Vice versa.
val user = Toml.decodeFromString(User.serializer(), tomlString)
// Print it.
println(user)
/*
User(name=Peanuuutz,account=Account(username=Peanuuutz,password=123456))
*/

// If you don't have a model class, try [TomlElement].
val config = Toml.parseToTomlTable(tomlString)
// Now you can access all the entries (this is an extension as "get by path").
val password = config["account", "password"]!!.toTomlLiteral().content

See also

Inheritors

Types

Link copied to clipboard
object Default : Toml

The default implementation of Toml with default configuration.

Properties

Link copied to clipboard
open override val serializersModule: SerializersModule

Functions

Link copied to clipboard
inline fun <T> Toml.decodeFromNativeReader(nativeReader: Reader): T

Deserializes the content of nativeReader into a value of type T using the serializer retrieved from reified type parameter.

inline fun <T> Toml.decodeFromNativeReader(nativeReader: Reader, vararg keys: Any?): T

Parses the content of nativeReader into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using the serializer retrieved from reified type parameter.

fun <T> Toml.decodeFromNativeReader(deserializer: DeserializationStrategy<T>, nativeReader: Reader): T

Deserializes the content of nativeReader into a value of type T using deserializer.

fun <T> Toml.decodeFromNativeReader(deserializer: DeserializationStrategy<T>, nativeReader: Reader, vararg keys: Any?): T

Parses the content of nativeReader into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using deserializer.

Link copied to clipboard
fun <T> decodeFromReader(deserializer: DeserializationStrategy<T>, reader: TomlReader): T

Deserializes the content of reader into a value of type T using deserializer.

fun <T> decodeFromReader(deserializer: DeserializationStrategy<T>, reader: TomlReader, vararg keys: Any?): T

Parses the content of reader into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using deserializer.

Link copied to clipboard
inline fun <T> Toml.decodeFromReader(reader: TomlReader): T

Deserializes the content of reader into a value of type T using the serializer retrieved from reified type parameter.

inline fun <T> Toml.decodeFromReader(reader: TomlReader, vararg keys: Any?): T

Parses the content of reader into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using the serializer retrieved from reified type parameter.

Link copied to clipboard
open override fun <T> decodeFromString(deserializer: DeserializationStrategy<T>, string: String): T

Deserializes string into a value of type T using deserializer.

fun <T> decodeFromString(deserializer: DeserializationStrategy<T>, string: String, vararg keys: Any?): T

Parses string into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using deserializer.

Link copied to clipboard
inline fun <T> Toml.decodeFromString(string: String, vararg keys: Any?): T

Parses string into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using the serializer retrieved from reified type parameter.

Link copied to clipboard
fun <T> decodeFromTomlElement(deserializer: DeserializationStrategy<T>, element: TomlElement): T

Deserializes element into a value of type T using deserializer.

Link copied to clipboard
inline fun <T> Toml.decodeFromTomlElement(element: TomlElement): T

Deserializes element into a value of type T using the serializer retrieved from reified type parameter.

Link copied to clipboard
inline fun <T> Toml.encodeToNativeWriter(value: T, nativeWriter: Writer)

Serializes value into nativeWriter using the serializer retrieved from reified type parameter.

fun <T> Toml.encodeToNativeWriter(serializer: SerializationStrategy<T>, value: T, nativeWriter: Writer)

Serializes value into nativeWriter using serializer.

Link copied to clipboard
inline fun <T> Toml.encodeToStream(value: T, outputStream: OutputStream)

Serializes value into outputStream using the serializer retrieved from reified type parameter.

fun <T> Toml.encodeToStream(serializer: SerializationStrategy<T>, value: T, outputStream: OutputStream)

Serializes value into outputStream using serializer.

Link copied to clipboard
open override fun <T> encodeToString(serializer: SerializationStrategy<T>, value: T): String

Serializes value into TOML string using serializer.

Link copied to clipboard
fun <T> encodeToTomlElement(serializer: SerializationStrategy<T>, value: T): TomlElement

Serializes value into TomlElement using serializer.

Link copied to clipboard
inline fun <T> Toml.encodeToTomlElement(value: T): TomlElement

Serializes value into TomlElement using the serializer retrieved from reified type parameter.

Link copied to clipboard
fun <T> encodeToWriter(serializer: SerializationStrategy<T>, value: T, writer: TomlWriter)

Serializes value into writer using serializer.

Link copied to clipboard
inline fun <T> Toml.encodeToWriter(value: T, writer: TomlWriter)

Serializes value into writer using the serializer retrieved from reified type parameter.

Link copied to clipboard

Parses string into equivalent representation of TomlTable.

Parses the content of reader into equivalent representation of TomlTable.

Link copied to clipboard

Parses the content of nativeReader into equivalent representation of TomlTable.