// IGNORE_BACKEND_K1: JS_IR // WITH_STDLIB import kotlinx.serialization.* import kotlinx.serialization.json.* // From #1264 @Serializable sealed class TypedSealedClass(val a: T) { @Serializable class Child(val y: Int) : TypedSealedClass("10") { override fun toString(): String = "Child($a, $y)" } } // From #KT-43910 @Serializable open class ValidatableValue( var value: T? = null, var error: V? = null, ) @Serializable class Email : ValidatableValue() { // Note this is a different T override fun toString(): String { return "Email($value, $error)" } } fun box(): String { val encodedChild = """{"a":"11","y":42}""" val decodedChild = Json.decodeFromString(encodedChild) if (decodedChild.toString() != "Child(11, 42)") return "DecodedChild: $decodedChild" Json.encodeToString(decodedChild)?.let { if (it != encodedChild) return "EncodedChild: $it" } val email = Email().apply { value = "foo" error = 1 } val encodedEmail = Json.encodeToString(email) if (encodedEmail != """{"value":"foo","error":1}""") return "EncodedEmail: $encodedEmail" val decodedEmail = Json.decodeFromString>(encodedEmail) if (decodedEmail.toString() != "Email(foo, 1)") return "DecodedEmail: $decodedEmail" return "OK" }