Created
October 13, 2021 01:03
-
-
Save navczydev/e2fc5c7b23c1fa0e82dbb0dcfce931f1 to your computer and use it in GitHub Desktop.
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
@OptIn(ExperimentalSerializationApi::class) | |
@Serializable | |
@JsonClassDiscriminator("languageType") | |
sealed class Language { | |
abstract val name: String | |
} | |
@Serializable | |
class Kotlin(override val name: String, private val version: String) : Language() { | |
fun getFormattedVersion(): String { | |
return version | |
} | |
} | |
@Serializable | |
class Java(override val name: String) : Language() | |
/* | |
Result: | |
{ | |
"languageType":"Kotlin", | |
"name":"Kotlin", | |
"version":"1.5.30" | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment