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.”

  • MostlyBlindGamer@rblind.com
    link
    fedilink
    English
    arrow-up
    9
    arrow-down
    1
    ·
    5 days ago

    Thanks for the transcription!

    Surely Java can tell the difference between a key with a null value and the absence of that key, no?

    I mean, you can set up your deserialization to handle nulls in different ways, but a string to object dictionary would capture this, right?

    • bleistift2@sopuli.xyzOP
      link
      fedilink
      English
      arrow-up
      16
      arrow-down
      2
      ·
      5 days ago

      Sure, Java can tell the difference. But that doesn’t mean that the guy writing the API cares whether or not he adds a key to the dictionary before yeeting it to the client.

    • Lysergid@lemmy.ml
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      4 days ago

      Kinda, I guess we all can agree it’s more typical to deserialize into POJO where theres is no such thing as missing field. Otherwise why would you choose Java if you don’t use types. This great precondition for various stupid hacks to achieve „patching” resources, like blank strings or negative numbers for positive-only fields or even Optional as a field.

    • AggressivelyPassive@feddit.de
      link
      fedilink
      arrow-up
      2
      ·
      5 days ago

      It can, but especially during serialization Java sometimes adds null references to null values.

      That’s usually a mistake by the API designer and/or Java dev, but happens pretty often.

      • MostlyBlindGamer@rblind.com
        link
        fedilink
        English
        arrow-up
        2
        ·
        4 days ago

        That’s the thing though, isn’t it? The devs on either side are entering into a contract (the API) that addresses this issue, even if by omission. Whoever breaks the contract must rightfully be ejected into the stratosphere.

        • AggressivelyPassive@feddit.de
          link
          fedilink
          arrow-up
          1
          ·
          4 days ago

          That’s exactly not the thing, because nobody broke the contract, they simply interpret it differently in details.

          Having a null reference is perfectly valid json, as long as it’s not explicitly prohibited. Null just says “nothing in here” and that’s exactly what an omission also communicates.

          The difference is just whether you treat implicit and explicit non-existence differently. And neither interpretation is wrong per contract.

          • MostlyBlindGamer@rblind.com
            link
            fedilink
            English
            arrow-up
            3
            ·
            4 days ago

            I think we’re fully in agreement here: if the API doesn’t specify how to handle null values, that omission means they’re perfectly valid and expected.

            Imagine a delivery company’s van exploding if somebody attempts to ship an empty box. That would be a very poorly built van.