Created
August 9, 2018 12:06
-
-
Save dhiraj/769fe4711fda1eb6e1aa7abcf1ea6de7 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
... | |
if(root is JsonArray && root.size() > 0){ //Smart cast 1 | |
val firstElem = root[0] | |
if(firstElem is JsonObject){ | |
val title = firstElem.get("title") //Smart cast 2 | |
if (title != null && title is JsonPrimitive && title.isString){ //Smart cast 3 | |
val titleString = title.asString | |
assertEquals("delectus aut autem",titleString) | |
} | |
val completed = firstElem.get("id") | |
if (completed != null && completed is JsonPrimitive && completed.isBoolean){ //Smart cast 4 | |
val completedBool = completed.asBoolean | |
assertFalse(completedBool) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment