Created
May 6, 2020 21:20
-
-
Save hissain/e97f2bfc152ac9c81ae4db3f8483cbed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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