Skip to content

Instantly share code, notes, and snippets.

@arnabkd
Created August 3, 2022 12:25
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 arnabkd/411e32e59fc78e032c5186c2584912b8 to your computer and use it in GitHub Desktop.
Save arnabkd/411e32e59fc78e032c5186c2584912b8 to your computer and use it in GitHub Desktop.
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
sealed class Principal
object AnonymousUser : Principal() {
val _empty: String? = null
}
// other implementations of Principal
fun main() {
// jacksonObjectMapper() is a function in jackson which creates an object mapper with the Kotlin module
val input = jacksonObjectMapper().writeValueAsString(AnonymousUser)
val principal = jacksonObjectMapper().readValue(input, Principal::class.java)
println(principal)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment