-
Notifications
You must be signed in to change notification settings - Fork 18.1k
encoding/json: adding a MarshalJSON method confuses JSON marshalling #67154
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
Comments
PS: Marshalling |
This is working as expected due to how methods for embedded types are promoted |
Why does a Can you please provide a reference/link to the documentation that describes this behaviour? |
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
Go version
go version go1.22.2 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I'm working with Kubernetes and custom resources. For logging and log filtering, I added a
MarshalJSON()
method to a struct field.Complete (vendored) source code: MarshalJson.zip
What did you see happen?
Calling json.Marshal()
on
MyObject2` generates only the output from MarshalJSON(), all other entities from o2 are missing.What did you expect to see?
I expect the two structures in my sample program to generate the same JSON output.
The text was updated successfully, but these errors were encountered: