Toml
The main entry point to use TOML.
User could simply use Default instance or customize by using creator function with the same name.
Basic usage:
@Serializable
data class User(
val name: String,
val account: Account? // Nullability
)
@Serializable
data class Account(
val username: String,
val password: String
)
// Now with [Default] instance
val user = User("Peanuuutz", Account("Peanuuutz", "123456"))
// 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"
*/
// And to reverse...
val user = Toml.decodeFromString(User.serializer(), tomlString)
// Print it
println(user)
// User(name=Peanuuutz,account=Account(username=Peanuuutz,password=123456))
// Or you're lazy to create model class, try [TomlElement]
val config = Toml.parseToTomlTable(tomlString)
// Now access to all entry (think you need getByPath)
val password: TomlLiteral = config["account", "password"]!!.toTomlLiteral()Content copied to clipboard
See also
Inheritors
Types
Functions
Link copied to clipboard
Deserializes string into a value of type T using deserializer.
Link copied to clipboard
Deserializes element into a value of type T using deserializer.
Link copied to clipboard
Link copied to clipboard
Serializes value into outputStream using 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
Serializes value into TOML string using serializer.
Link copied to clipboard
Serializes value into TomlElement using serializer.
Link copied to clipboard
Serializes value into TomlElement using serializer retrieved from reified type parameter.
Link copied to clipboard
Serializes value into writer using serializer.
Link copied to clipboard
Link copied to clipboard