<@U092308M7>: I have this code: ``` interface Cont...
# random
k
@orangy: I have this code:
Copy code
interface Contact {
    val id: Long
    val address: String
    val notes: String?
    val kind: String
}

class ContactSerializer : JsonSerializer<Contact> {

    override fun serialize(src: Contact, typeOfSrc: Type, context: JsonSerializationContext) =
            JsonObject().apply {
                addProperty("id", src.id)
                addProperty("address", src.address)
                addProperty("notes", src.notes)
                addProperty("kind", src.kind)
            }

}

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().registerTypeAdapter(Contact::class.java, ContactSerializer()).create()
    println(gson.toJson(contact))
    println(gson.toJson(contact, Contact::class.java))
}
which prints:
Copy code
null
{"id":13,"address":"foo","notes":"bar","kind":"apple"}