Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/json: RawMessage should marshal without pointer receiver #6528
The current json.RawMessage implementation defines MarshalJSON on a pointer receiver. This causes unexpected behavior when marshalling with non-pointer-receiver objects. For example: http://play.golang.org/p/Cf_6zpIKC0 Instead, MarshalJSON should be defined on a non-pointer receiver for json.RawMessage. This will continue to work for existing code that uses pointer-receivers, but will change behavior to work "correctly" on code that accidentally uses non-pointer-receivers.
What's the solution here? Adding a comment to http://golang.org/src/pkg/encoding/json/stream.go?s=4434:4484#L175 to warn that calling json.Marshal on a non-pointer json.RawMessage can return "meaningless" data with err == nil