We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
omitempy
type OmitEmptyInterface struct { ErrCode int32 `json:"code"` Data interface{} `json:"data,omitempty"` } func TestOmitEmptyInterface(t *testing.T) { // non-enmpty type var data *string resp := &OmitEmptyInterface{ ErrCode: 123, Data: data, } eout, eerr := json.Marshal(resp) sout, serr := sonic.Marshal(resp) require.Equal(t, eerr == nil, serr == nil) require.Equal(t, string(eout), string(sout)) // empty type and value resp = &OmitEmptyInterface{ ErrCode: 123, Data: nil, } eout, eerr = json.Marshal(resp) sout, serr = sonic.Marshal(resp) require.Equal(t, eerr == nil, serr == nil) require.Equal(t, string(eout), string(sout)) }
output
--- FAIL: TestOmitEmptyInterface (0.00s) /Users/admin/GOPATH/work/sonic/issue_test/issuexx_test.go:40: Error Trace: /Users/admin/GOPATH/work/sonic/issue_test/issuexx_test.go:40 Error: Not equal: expected: "{\"code\":123,\"data\":null}" actual : "{\"code\":123}" Diff: --- Expected +++ Actual @@ -1 +1 @@ -{"code":123,"data":null} +{"code":123} Test: TestOmitEmptyInterface
sonic check if a interface is empty using second field emptyInterface.word, while std lib using first field emptyInterface.typ
emptyInterface.word
emptyInterface.typ
The text was updated successfully, but these errors were encountered:
#540
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Reproducible codes
output
Explaination
sonic check if a interface is empty using second field
emptyInterface.word
, while std lib using first fieldemptyInterface.typ
The text was updated successfully, but these errors were encountered: