https://kotlinlang.org logo
#random
Title
# random
k

kirillrakhman

06/27/2016, 2:05 PM
this code
Copy code
class ConcreteContact : Contact {
    override val id: Long get() = 13
    override val address: String get() = "foo"
    override val notes: String? get() = "bar"
    override val kind: String get() = "apple"
}

fun main(args: Array<String>) {
    val contact = object : Contact {
        override val id: Long get() = 13
        override val address: String get() = "foo"
        override val notes: String? get() = "bar"
        override val kind: String get() = "apple"
    }

    val gson = GsonBuilder().registerTypeHierarchyAdapter(Contact::class.java, ContactSerializer()).create()
    println(gson.toJson(contact))
    println(gson.toJson(ConcreteContact()))
}
now prints
Copy code
null
{"id":13,"address":"foo","notes":"bar","kind":"apple"}