You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the provided code, when unmarshalling the JSON the Weight attribute is correctly set to present: 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 of null. This is unexpected as I would assume Present: false would omit the attribute from the marshalled JSON (and that the marshalled JSON should match the original JSON).
Steps to Reproduce
Run the following code: (modified from this example in the project README.md)
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:
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: