- cross-posted to:
- programmer_humor@programming.dev
- cross-posted to:
- programmer_humor@programming.dev
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.”
- remotelove ( @remotelove@lemmy.ca ) 13•3 months ago
I don’t get it. The key still gets declared, but it’s value is null. “name” in an empty object would return undefined, not null, correct?
(Yes, this joke whooshed, but I am curious now.)
Indeed, and that turns out to be a problem if the JavaScript expects the key not to be there, but instead it is there. And then you try to tell the backend dev that the key shouldn’t be there, but he’ll try to convince you that it’s the same whether the key is not there or whether it’s assigned
null
and then you wonder if he’s messing with you, but actually he isn’t and then the only thing keeping you sane is bitching about it in meme form on lemmy.- PeriodicallyPedantic ( @PeriodicallyPedantic@lemmy.ca ) 1•3 months ago
For many uses it is semantically the same.
But for cases where you need to know if something was intentionally set to null or was simply not set, the difference is enormous.
- Dunstabzugshaubitze ( @Dunstabzugshaubitze@feddit.org ) 7•3 months ago
there is no “undefined” in java. this would either be a map containing the key value pair (“name”, null) or it would be mapped to an object of some class with an attribute “name” which can hold a null value. in any case {} wont equal {“name”:null}.
- deadbeef79000 ( @deadbeef79000@lemmy.nz ) 6•3 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
- apprehentice ( @apprehentice@lemmy.enchanted.social ) English6•3 months ago
C# devs be like
public string? Name { get; set; }
- hedgehog ( @hedgehog@ttrpg.network ) 5•3 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
- PeriodicallyPedantic ( @PeriodicallyPedantic@lemmy.ca ) 4•3 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.
- jsomae ( @jsomae@lemmy.ml ) 3•3 months ago
This is true in Lua as well (substituting ‘nil’ for 'null)
- beefsquatch ( @beefsquatch@programming.dev ) 3•3 months ago
{"name": undefined}
is also different, checking with something like hasOwn - Gamma ( @GammaGames@beehaw.org ) English1•3 months ago
That’s what undefined is for
- magic_lobster_party ( @magic_lobster_party@kbin.run ) 5•3 months ago
Undefined is not part of JSON specification. It’s also not a thing in Java.
- Gamma ( @GammaGames@beehaw.org ) English1•3 months ago
Yeah my bad, it would still require the java dev to leave the keys out
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 }
vsconst obj = {}