forked from Kotlin/kotlinx.serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-json-11.kt
31 lines (22 loc) · 838 Bytes
/
example-json-11.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// This file was automatically generated from json.md by Knit tool. Do not edit.
package example.exampleJson11
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
@JsonClassDiscriminator("message_type")
sealed class Base
@Serializable // Class discriminator is inherited from Base
sealed class ErrorClass: Base()
@Serializable
data class Message(val message: Base, val error: ErrorClass?)
@Serializable
@SerialName("my.app.BaseMessage")
data class BaseMessage(val message: String) : Base()
@Serializable
@SerialName("my.app.GenericError")
data class GenericError(@SerialName("error_code") val errorCode: Int) : ErrorClass()
val format = Json { classDiscriminator = "#class" }
fun main() {
val data = Message(BaseMessage("not found"), GenericError(404))
println(format.encodeToString(data))
}