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
The current json package can't handle non-pointer struct encoding alongside with omitempty tag. This means we need to add the structs as pointers. Many of the proposals have been submitted. This is the main ticket dealing with this problem: #11939
I tried to go to an other direction in this proposal, because the major problem with the IsZero, that it's not backward compatible.
Possible solution
I think we need to use the encOpts located in the json/encode.go. By using it we can setup a solution which can handle this problem and just like the SetIndent, it can be called over the Encoder struct.
One possible example can be the SetOmitemptyOnIsZero(b bool), which omitting the value if the IsZero function of the given struct returns true. (Note, the naming conventions isn't good, it's just something for showing the idea.)
Problem
The current json package can't handle non-pointer struct encoding alongside with omitempty tag. This means we need to add the structs as pointers. Many of the proposals have been submitted. This is the main ticket dealing with this problem: #11939
I tried to go to an other direction in this proposal, because the major problem with the IsZero, that it's not backward compatible.
Possible solution
I think we need to use the
encOpts
located in thejson/encode.go
. By using it we can setup a solution which can handle this problem and just like theSetIndent
, it can be called over the Encoder struct.One possible example can be the
SetOmitemptyOnIsZero(b bool)
, which omitting the value if the IsZero function of the given struct returns true. (Note, the naming conventions isn't good, it's just something for showing the idea.)Implementation details: https://github.com/PumpkinSeed/go-json-proposal/pull/1/files
The text was updated successfully, but these errors were encountered: