Skip to content
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

not consistent with encoding/json when marshalling struct field with "omitempty" tag #113

Closed
liuq19 opened this issue Oct 9, 2021 · 0 comments · Fixed by #114
Closed

Comments

@liuq19
Copy link
Collaborator

liuq19 commented Oct 9, 2021

code

type Struct struct {
    F1   struct{ F2 string} `json:",omitempty"`
}
func TestMarshalStructFieldWithOmitemptyTag(t *testing.T) {
    var obj Struct

    out, err := Marshal(obj)
    require.NoError(t, err)

    want, err := json.Marshal(obj)
    require.NoError(t, err)

    require.Equal(t, string(want), string(out))
}

output

        	Error:      	Not equal:
        	            	expected: "{\"F1\":{\"F2\":\"\"}}"
        	            	actual  : "{}"

        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-{"F1":{"F2":""}}
        	            	+{}
        	Test:       	TestMarshalStructFieldWithOmitemptyTag
@liuq19 liuq19 changed the title not idempotent when marshalling nested slice filed with "omitempty" tag not consistent with encoding/json when marshalling struct field with "omitempty" tag Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant