encoding/json has an example for Unmarshalling json.RawMessage but not for Marshalling it. The example doesn't point out that Marshalling requires a *RawMessage. Using RawMessage doesn't give the expected results and it's not immediately obvious why. https://play.golang.org/p/A1nbikzzVY
The text was updated successfully, but these errors were encountered:
josharian
changed the title
doc encoding/json: explain how to properly Marshall RawMessage
encoding/json: explain how to properly Marshall RawMessage
Aug 10, 2016
I think it makes sense adding such example, namely because the documentation says it can be used both to delay parsing as much to precompute a JSON encoding - the latter missing. Likely something along the lines: https://play.golang.org/p/OdTp9Dh0o1
I believe it to be a bit misleading to say that is better to call always json.Marshal(&v). json.Marshal will execute json.Marshaler of pointers, otherwise it will just take the concrete type and marshal it.
encoding/json has an example for Unmarshalling
json.RawMessage
but not for Marshalling it. The example doesn't point out that Marshalling requires a*RawMessage
. UsingRawMessage
doesn't give the expected results and it's not immediately obvious why.https://play.golang.org/p/A1nbikzzVY
The text was updated successfully, but these errors were encountered: