Skip to content

time: Time Zero MarshalJSON / UnmarshalJSON produces a different object #10089

@simon3z

Description

@simon3z

It seems that marshaling and unmarshaling a zero time produces an object that is different from the original:

func TestMarshalUnmarshalJSON(t *testing.T) {
        var expected, parsed Time

        body, err := expected.MarshalJSON()
        if err != nil {
                t.Errorf("json.Marshal error = %v", err)
        }

        err = parsed.UnmarshalJSON(body)
        if err != nil {
                t.Errorf("json.Unmarshal error = %v", err)
        }

        if !reflect.DeepEqual(expected, parsed) {
                t.Errorf("json error, expected = %#v, parsed = %#v", expected, parsed)
        }
}

--- FAIL: TestMarshalUnmarshalJSON (0.00 seconds)
        time_test.go:807: json error, expected = time.Time{sec:0, nsec:0x0, loc:(*time.Location)(nil)}, parsed = time.Time{sec:0, nsec:0x0, loc:(*time.Location)(0x6cd2a0)}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions