Hexa
07/17/2018, 6:14 PMimport com.fasterxml.jackson.databind.ObjectMapper
fun main ( args : Array < String > ) {
val mapper = ObjectMapper()
val jsonResult = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(someString)
System.out.println("blank: ${jsonResult.isBlank()}")
System.out.println("isEmpty: ${jsonResult.isEmpty()}")
System.out.println("{}: ${jsonResult.contentEquals("{}")}")
}
jsonResult
returns {}
in my logs which means its a an empty json. How do I check if jsonResult is equals to {}
(or empty). All of my println returns false
, so isEmpty
and isBlank
dont work.Nikky
07/17/2018, 6:52 PMkt
val someString = "{}"
val mapper = ObjectMapper()
val jsonResult = mapper.readTree(someString)
println(jsonResult.nodeType)
if(jsonResult is ObjectNode) {
println(jsonResult.size())
}
jsonResult.size() == 0
Hexa
07/17/2018, 8:50 PM