Meme transcription: Panel 1. Two images of JSON, one is the empty object, one is an object in which the key name maps to the value null. Caption: “Corporate needs you to find the difference between this picture and this picture”

Panel 2. The Java backend dev answers, “They’re the same picture.”

  • Excel@lemmy.megumin.org
    link
    fedilink
    arrow-up
    10
    arrow-down
    2
    ·
    edit-2
    5 days ago

    If you’re branching logic due to the existence or non-existence of a field rather than the value of a field (or treating undefined different from null), I’m going to say you’re the one doing something wrong, not the Java dev.

    These two things SHOULD be treated the same by anybody in most cases, with the possible exception of rejecting the later due to schema mismatch (i.e. when a “name” field should never be defined, regardless of the value).

    • sik0fewl@lemmy.ca
      link
      fedilink
      arrow-up
      4
      arrow-down
      1
      ·
      4 days ago

      Ya, having null semantics is one thing, but having different null and absent/undefined semantics just seems like a bad idea.

      • Username@feddit.de
        link
        fedilink
        arrow-up
        6
        ·
        4 days ago

        Not really, if absent means “no change”, present means “update” and null means “delete” the three values are perfectly well defined.

        For what it’s worth, Amazon and Microsoft do it like this in their IoT offerings.