Skip to content

Instantly share code, notes, and snippets.

@navczydev
Created October 13, 2021 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navczydev/e2fc5c7b23c1fa0e82dbb0dcfce931f1 to your computer and use it in GitHub Desktop.
Save navczydev/e2fc5c7b23c1fa0e82dbb0dcfce931f1 to your computer and use it in GitHub Desktop.
@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