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

  • expr@programming.dev
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    5 months ago

    The semantics of the API contract is distinct from its implementation details (lazy loading).

    Treating null and undefined as distinct is never a requirement for general-purpose API design. That is, there is always an alternative design that doesn’t rely on that misfeature.

    As for patches, while it might be true that JSON Merge Patch assigns different semantics to null and undefined values, JSON Merge Patch is a worse version of JSON Patch, which doesn’t have that problem, because like I originally described, the semantics are explicit in the data structure itself. This is a transformation that you can always apply.

    • masterspace@lemmy.ca
      link
      fedilink
      English
      arrow-up
      3
      arrow-down
      1
      ·
      edit-2
      5 months ago

      No there isn’t.

      Tell me how you partially change an object.

      Object User :

      { Name: whatever, age: 0}

      Tell me how you change the name without knowing the age. You fundamentally cannot, meaning that you either have to shuttle useless information back and forth constantly so that you can always patch the whole object, or you have to create a useless and unscalable number of endpoints, one for every possible field change.

      As others have roundly pointed out, it is asinine to generally assume that undefined and null are the same thing, and no, it flat out it is not possible to design around that, because at a fundamental level those are different statements.

      • expr@programming.dev
        link
        fedilink
        arrow-up
        0
        arrow-down
        2
        ·
        5 months ago

        As I already said, it’s very simple with JSON Patch:

        [
          { *op": "replace", "path": "/Name™, "value": "otherName"}
        ]
        

        Good practice in API design is to permissively accept either undefined or null to represent optionality with same semantics (except when using JSON Merge Patch, but JSON Patch linked above should be preferred anyway).

        • masterspace@lemmy.ca
          link
          fedilink
          English
          arrow-up
          3
          arrow-down
          4
          ·
          edit-2
          5 months ago

          I.e. waste a ton of bandwidth sending a ridiculous amount of useless data in every request, all because your backend engineers don’t know how to program for shit.

          Gotcha.

          • expr@programming.dev
            link
            fedilink
            arrow-up
            2
            ·
            5 months ago

            It’s about making APIs more flexible, permissive, and harder to misuse by clients. It’s a user-centric approach to API design. It’s not done to make it easier on backend. If anything, it can take extra effort by backend developers.

            But you’d clearly prefer vitriol to civil discourse and have no interest in actually learning anything, so I think my time would be better spent elsewhere.