Closed openly-engineering closed 5 years ago
@mwielbut thanks for the PR! I agree this makes sense. I'll create a new minor release and note that it's a breaking change.
Would you mind removing the go mod files from the PR? I haven't yet switched the project over from dep but am planning to soon.
Awesome! Just removed the go.mod
and go.sum
files. We needed them to make it work locally with modules but it should be fine once it's in your release.
Cheers! Thanks again!
The current implementation marshals non-present values as their zero value. When the zero values are read back in, we lose the fidelity of knowing that the value was actually not-present vs. explicitly set to the zero value (the whole purpose of using the optional library). I don't think this should be expected outcome.
This pull request proposes a modification to the
UnmarshalJSON
andMarshalJSON
functions, marshaling JSONnull
when the value isnil
, and unmarshaling JSONnull
tonil
. This seems to be more in-line with what should be expected when writing this out to JSON.Note: this is a breaking change for dependents that rely on the existing functionality of marshaling to the zero value.
Thanks!