Roman Elizarov | 5459c10 | 2020-08-11 12:27:36 +0300 | [diff] [blame] | 1 | // This file was automatically generated from README.md by Knit tool. Do not edit. |
| 2 | package example.exampleReadme01 |
| 3 | |
| 4 | import kotlinx.serialization.* |
| 5 | import kotlinx.serialization.json.* |
| 6 | |
| 7 | @Serializable |
| 8 | data class Project(val name: String, val language: String) |
| 9 | |
| 10 | fun 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 Tolstopyatov | fbf59d2 | 2020-08-15 17:38:51 +0300 | [diff] [blame] | 17 | println(obj) // Project(name=kotlinx.serialization, language=Kotlin) |
Roman Elizarov | 5459c10 | 2020-08-11 12:27:36 +0300 | [diff] [blame] | 18 | } |