Skip to content

Instantly share code, notes, and snippets.

@dhiraj
Created August 9, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhiraj/769fe4711fda1eb6e1aa7abcf1ea6de7 to your computer and use it in GitHub Desktop.
Save dhiraj/769fe4711fda1eb6e1aa7abcf1ea6de7 to your computer and use it in GitHub Desktop.
...
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