blob: c241188f903872323a7f276528ab2dfab4b8dc93 [file] [log] [blame]
Roman Elizarov5459c102020-08-11 12:27:36 +03001// This file was automatically generated from README.md by Knit tool. Do not edit.
2package example.exampleReadme01
3
4import kotlinx.serialization.*
5import kotlinx.serialization.json.*
6
7@Serializable
8data class Project(val name: String, val language: String)
9
10fun main() {
11 // Serializing objects
12 val data = Project("kotlinx.serialization", "Kotlin")
13 val string = Json.encodeToString(data)
14 println(string) // {"name":"kotlinx.serialization","language":"Kotlin"}
15 // Deserializing back into objects
16 val obj = Json.decodeFromString<Project>(string)
Vsevolod Tolstopyatovfbf59d22020-08-15 17:38:51 +030017 println(obj) // Project(name=kotlinx.serialization, language=Kotlin)
Roman Elizarov5459c102020-08-11 12:27:36 +030018}