Toml
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().contentSee also
Inheritors
Types
Functions
Deserializes the content of nativeReader into a value of type T using the serializer retrieved from reified type parameter.
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.
Deserializes the content of nativeReader into a value of type T using deserializer.
Parses the content of nativeReader into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using deserializer.
Deserializes the content of reader into a value of type T using deserializer.
Parses the content of reader into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using deserializer.
Deserializes string into a value of type T using deserializer.
Parses string into a TomlTable and deserializes the corresponding element fetched with keys into a value of type T using deserializer.
Deserializes element into a value of type T using deserializer.
Serializes value into nativeWriter using the serializer retrieved from reified type parameter.
Serializes value into nativeWriter using serializer.
Serializes value into outputStream using the serializer retrieved from reified type parameter.
Serializes value into outputStream using serializer.
Serializes value into TOML string using serializer.
Serializes value into TomlElement using serializer.
Serializes value into TomlElement using the serializer retrieved from reified type parameter.
Serializes value into writer using serializer.
Parses the content of nativeReader into equivalent representation of TomlTable.