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

  • PeriodicallyPedantic@lemmy.ca
    link
    fedilink
    arrow-up
    10
    ·
    4 months ago

    Ah yes the difference between “unset” and “intentionally set to null”, the bane of API devs who work in languages that don’t inherently distinguish between the two.

  • deadbeef79000@lemmy.nz
    link
    fedilink
    arrow-up
    9
    ·
    4 months ago

    Well. To Java that’s just a string of utf-8 characters, assuming you haven’t bastardised the encoding, and it’s just yanked out of an HTTP entity. So of course they’re different.

    If you’re using some json parser and object mapping library (like Jackson) then all bets are off 'cause it could be configured any which way.

    On every other language and library it’s whatever the defined behaviour is.

    3/10

  • hedgehog@ttrpg.network
    link
    fedilink
    arrow-up
    9
    ·
    4 months ago

    If your Java dev is using Jackson to serialize to JSON, they might not be very experienced with Jackson, or they might think that a Java object with a null field would serialize to JSON with that field omitted. And on another project that might have been true, because Jackson can be configured globally to omit null properties. They can also fix this issue with annotations at the class/field level, most likely @JsonInclude(Include.NON\_NULL).

    More details: https://www.baeldung.com/jackson-ignore-null-fields

  • gravitas_deficiency@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    4 months ago

    That’s not legal serialized json, in the context of how any lib in Java (that I’m aware of) would either parse or render it.

    Ignore me, I misremembered, sorry about that.

      • Gamma@beehaw.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 months ago

        Yeah my bad, it would still require the java dev to leave the keys out

    • bleistift2@sopuli.xyzOP
      link
      fedilink
      English
      arrow-up
      4
      ·
      4 months ago

      To be fair, just because obj.foo is undefined, that doesn’t mean the key is missing. It could also be assigned the value undefined. const obj = { foo: undefined } vs const obj = {}