Created
January 20, 2022 18:06
-
-
Save buijs-dev/f7d197bce7ab44578cf7bc1c568aa6a2 to your computer and use it in GitHub Desktop.
serialize with kotlinx from superclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Parent | |
@Serializable | |
abstract class KlutterJSON<T>( | |
private val serializer: SerializationStrategy<T>, | |
){ | |
//todo need reference to child class body to serialize it | |
fun toKJson() = Json.encodeToString(serializer, ????) | |
//Doesnt work obviously: | |
//fun toKJson() = Json.encodeToString(serializer, this) | |
} | |
//Child | |
@Serializable | |
class Foo(val bar: String): KlutterJSON<Foo>(serializer()) | |
@Test | |
fun shouldTest() { | |
assertEquals("""{"bar":"boo"}""", Foo(bar = "boo").toKJson()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment