Menu

#70 "null" == null '??? not really... but...

open-invalid
aalmiray
None
5
2009-09-10
2008-07-23
Anonymous
No

Hi,

I re-open 1881483 because "null" strings are still sent as null instead of "null".

For my project this is an issue because if in the GUI one user enters the string 'null' (without quotes) in a inputBox and save it, when edited again the inputBox is empty (because it received null) instead of showing null (if it had received "null").

The probleme comes from Class JSONObject, method _fromString that does
if(str == null || "null".equals(str))

This is really a bug... why would you want to convert the string "null" to a null value??? In java (and javascript BTW) the string "null" and the null reference have different meanings and they should be kept...

Please just remove || "null".equals(str) and I'll be happy ;->

thx

vincent

Discussion

  • aalmiray

    aalmiray - 2008-07-24

    Logged In: YES
    user_id=1192026
    Originator: NO

    Vincent,

    Given JSONNull's javadoc: JSONNull is equivalent to the value that JavaScript calls null, whilst Java's null is equivalent to the value that JavaScript calls undefined. Which means that "null" should be treated as JS null, now because json String values cannot be null (only objects can) this case returns an empty String.

    But there are alternatives to modify the default behavior, you may register a custom filter or a JsonValueProcessor, just remember that what you really need is the following Java string: "\"null\"".

    Cheers,
    Andres

     
  • aalmiray

    aalmiray - 2008-07-24
    • assigned_to: nobody --> aalmiray
     
  • aalmiray

    aalmiray - 2008-10-18
    • status: open --> closed
     
  • aalmiray

    aalmiray - 2008-10-18
    • status: closed --> closed-invalid
     
  • Nick H

    Nick H - 2009-09-10

    Even though this bug has been closed, I agree with Vincent. Whatever your philosophical views on null vs undefined are, "null" is never null. There is no need to bring strings into it, and there's no reason for these four characters in a string to magically turn into the null value.

     
  • Nick H

    Nick H - 2009-09-10
    • status: closed-invalid --> open-invalid
     
  • Nobody/Anonymous

    I agree with vincent and csucew, this is only a philosophical view that behaves as a bug. "null" is NEVER null. More over if you try to add a null String element to a JSONObject, the property is simply not set, so you do not need to perform the "magic" conversion.

    Thanks,

    Roberto

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.