Roman Elizarov | 5459c10 | 2020-08-11 12:27:36 +0300 | [diff] [blame] | 1 | // This file was automatically generated from polymorphism.md by Knit tool. Do not edit. |
| 2 | package example.examplePoly07 |
| 3 | |
| 4 | import kotlinx.serialization.* |
| 5 | import kotlinx.serialization.json.* |
| 6 | |
| 7 | @Serializable |
Roman Elizarov | 2f4d91c | 2021-05-17 18:53:04 +0300 | [diff] [blame] | 8 | sealed class Project { |
| 9 | abstract val name: String |
| 10 | var status = "open" |
| 11 | } |
| 12 | |
Roman Elizarov | 5459c10 | 2020-08-11 12:27:36 +0300 | [diff] [blame] | 13 | @Serializable |
Roman Elizarov | 2f4d91c | 2021-05-17 18:53:04 +0300 | [diff] [blame] | 14 | @SerialName("owned") |
| 15 | class OwnedProject(override val name: String, val owner: String) : Project() |
Roman Elizarov | 5459c10 | 2020-08-11 12:27:36 +0300 | [diff] [blame] | 16 | |
| 17 | fun main() { |
Roman Elizarov | 2f4d91c | 2021-05-17 18:53:04 +0300 | [diff] [blame] | 18 | val json = Json { encodeDefaults = true } // "status" will be skipped otherwise |
| 19 | val data: Project = OwnedProject("kotlinx.coroutines", "kotlin") |
| 20 | println(json.encodeToString(data)) |
Roman Elizarov | 5459c10 | 2020-08-11 12:27:36 +0300 | [diff] [blame] | 21 | } |