I think it's a misuse of json.RawMessage.
what do you expect the output to be for the first marshal call?
{"tasks":[{"creds":null}]} is not the correct answer.
The content of RawMessage is the raw json data,
so it's impossible for a RawMessage to be nil or []byte{}.
Think how you can parse a valid json into a RawMessage
so that it's nil or []byte{}.
That's because the MarshalJSON method of json.RawMessage
is defined on a pointer receiver, so if you pass a json.RawMessage
to Marshal, it will be treated the same as a []byte and not as
a RawMessage.
https://play.golang.org/p/_253EEfKke
minux
changed the title
encoding/json behaves incorrectly on nested structs
encoding/json: behaves incorrectly on nested structs with json.RawMessage
Apr 24, 2015
Example here: https://play.golang.org/p/lozTmQr8pR
I'd expect all three outputs to be sane json. There should be no errors here.
The text was updated successfully, but these errors were encountered: