Skip to content

Unmarshalling null into struct fails in JSONry but not standard library #14

@blgm

Description

@blgm

This code using encoding/json does not generate an error:

func main() {
	data := `{"foo": null}`

	type a struct {
		Bar string `json:"bar"`
	}

	type b struct {
		Foo a `json:"foo"`
	}

	var v b
	err := json.Unmarshal([]byte(data), &v)
	if err != nil {
		panic(err)
	}
}

But this almost identical code using JSONry does:

func main() {
	data := `{"foo": null}`

	type a struct {
		Bar string `json:"bar"`
	}

	type b struct {
		Foo a `json:"foo"`
	}

	var v b
	err := jsonry.Unmarshal([]byte(data), &v)
	if err != nil {
		panic(err)
	}
}

Where possible JSONry should behave like encoding/json and this seems to be a situation where JSONry could easily be changed to be consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions