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

Serializing struct with embedded interface results in malformed json #426

Closed
ty-sentio-xyz opened this issue Feb 3, 2023 · 0 comments · Fixed by #431
Closed

Serializing struct with embedded interface results in malformed json #426

ty-sentio-xyz opened this issue Feb 3, 2023 · 0 comments · Fixed by #431

Comments

@ty-sentio-xyz
Copy link

Example:

type I interface {
	Foo()
}

type A struct {
	I
	Val string
}

func TestStructWithEmbeddedInterface(t *testing.T) {
	var s A
	s.Val = "456"

	j1, _ := json.Marshal(s)  // This uses encoding/json.
	fmt.Println("expected", string(j1))

	j2, _ := goccyjson.Marshal(s)  // This uses this library.
	fmt.Println("actual", string(j2))
}

The code above will generate a json string that is not valid.

Expected result (using encoding/json):
{"I":null,"Val":"456"}

Actual result:
{null,"Val":"456"}

This can be reproduced with:
github.com/goccy/go-json v0.10.0

orisano added a commit to orisano/go-json that referenced this issue Feb 24, 2023
orisano added a commit to orisano/go-json that referenced this issue Feb 24, 2023
goccy added a commit that referenced this issue Mar 13, 2023
fix: fixed handling of anonymous fields other than struct
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