Skip to content

encoding/json: regression in handling of nil RawMessage #17704

Closed
@dsnet

Description

@dsnet

1625da2 (issue: #14493, CL: http://golang.org/cl/21811) caused a regression where the a nil RawMessage no longer gets marshaled as "null".

Consider the following:

var nilJSON json.RawMessage
b, err := json.Marshal(nilJSON)
fmt.Printf("%q\t%v\n", b, err)
b, err = json.Marshal(&nilJSON)
fmt.Printf("%q\t%v\n", b, err)

On Go 1.7, this prints:

"null"	<nil>
""	json: error calling MarshalJSON for type *json.RawMessage: unexpected end of JSON input

On 1625da2, this prints:

""	json: error calling MarshalJSON for type json.RawMessage: unexpected end of JSON input
""	json: error calling MarshalJSON for type *json.RawMessage: unexpected end of JSON input

In light of the change to address #14493, I expect this to print:

"null"	<nil>
"null"	<nil>

Does anyone object if I make this change?

\cc @bradfitz @rsc

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions