0

when iterate through a List of JSONNODES like so

 for(JsonNode result: results){
   if (predicate==Predicate.GREATER_THAN && result.has("JarVersion")){
        //gets in here even though 'JarVersion' is null
        if(result.get("JarVersion").textValue().compareTo(version) > 0)
          //fails here because nulls pass through

for some reason even though result.get("JarVersion") returns null, it passes the result.has() check.

Is there an issue with the has() function of this library?

I looked into it and on the interface all it is doing is results.get(fieldName) != null, yet there are many null cases that get through (and break) my code

sf8193
  • 575
  • 1
  • 6
  • 25
  • 1
    I think you want to use `asText()` instead of `textValue()`. `"for non-String values (ones for which isTextual() returns false) null will be returned."` - this is from javadoc at `textValue()` method. – KunLun May 07 '19 at 17:05
  • I think I found the issue. In the documentation... ```NOTE: this method will return true for explicitly added * null values ``` – sf8193 May 07 '19 at 17:05
  • @KunLun nice catch! Thanks – sf8193 May 07 '19 at 17:10
  • I say that because I think `result.has("JarVersion")` is `true`, but `textValue()` can't convert value to `String`. P.S.: so i was right? – KunLun May 07 '19 at 17:12
  • @KunLun nope, I thought it would, but still doesn't work. I check like this ```!result.get("JarVersion").asText("").equals("")``` and this ```result.get("JarVersion") != null```, but I still get empty strings coming through – sf8193 May 07 '19 at 17:42
  • Can you give us some sample of json? – KunLun May 07 '19 at 17:48
  • 1
    you know what, I a different issue that I assumed led to this one, I apoglogize, it was an issue on my front end. The two checks we found do make it work (where it wasn't before). – sf8193 May 07 '19 at 17:49

0 Answers0