Skip to content

omitempty in combination with zero values and empty slices/maps isn't creating patches as expected #2

Description

@snorwin

There is currently no logic to handle omitempty and zero value properly. The same applies if all elements of a map or slice are deleted.

Example

type Person struct {
	Name string `json:"name"`
	Age  int    `json:"age,omitempty"`
}

original := &Person{
	Name: "John Doe",
	Age:  42,
}
updated := &Person{
	Name: "John Doe",
}

patch, _ := jsonpatch.CreateJSONPatch(updated, original)

Expected result

[{"op":"remove","path":"/age"}]

Actual result

[{"op":"replace","path":"/age","value":0}]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingv2

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions