Skip to content

Instantly share code, notes, and snippets.

@hissain
Created May 6, 2020 21:20
Show Gist options
  • Save hissain/e97f2bfc152ac9c81ae4db3f8483cbed to your computer and use it in GitHub Desktop.
Save hissain/e97f2bfc152ac9c81ae4db3f8483cbed to your computer and use it in GitHub Desktop.
data class Student(
var name: String? = null,
var address: String? = null) {
}
class StudentDeserializer : JsonDeserializer<Student> {
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Student {
json as JsonObject
val name = json.get("name").asString
val addressJson = json.get("address")
val address = if (addressJson.isJsonObject) addressJson.asJsonObject.toString() else addressJson.asString
return Student(name, address)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment