-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Marshalled JSON includes attributes with Present: false
#21
Comments
@skplunkerin thanks for opening an issue. Weight *gonull.Nullable[string] `json:"weight,omitempty"` I'll work on it to fix this issue ASAP. |
+1 for this, it also doesn't seem to work correctly when omitempty is specified and it's not a pointer to a gonull.Nullable. |
Just to keep you updated, after a long debate, very recently, actually, last month, they decided to accept the fact that check zeroed values for structs, when marshaling is something important. They introduced a new tag type Foo struct {
ID gonull.Nullable[int64] `json:"id,omitempty,omitzero"`
Name gonull.Nullable[string] `json:"name,omitempty,omitzero"`
Ready gonull.Nullable[bool] `json:"ready,omitempty,omitzero"`
} and the most important, use Best cc: @skplunkerin , @LukaGiorgadze , @rob2244 |
This is exactly what I was waiting for. Thanks, @alvesoaj, for the update! |
I also created this PR: #23 to introduce a helping function. @LukaGiorgadze |
In the provided code, when unmarshalling the JSON the
Weight
attribute is correctly set topresent: false, valid: false
as"Weight"
isn't specified in the JSON.However, when marshalling the struct back to JSON the output includes the
Weight
attribute with a value ofnull
. This is unexpected as I would assumePresent: false
would omit the attribute from the marshalled JSON (and that the marshalled JSON should match the original JSON).Steps to Reproduce
README.md
)Expected Behavior
The marshalled JSON should not include the
Weight
attribute as it was not present in the original JSON (Present: false
):Actual Behavior
The marshalled JSON includes the
Weight
attribute with a value ofnull
:Environment
1.22
gonull
version:1.2.0
Additional Context
This issue was discovered while testing the unmarshalling and marshalling of JSON data with optional fields in the Go Playground. The expected behavior is based on the assumption that
Present: false
should result in the attribute being omitted from the marshalled JSON.The text was updated successfully, but these errors were encountered: