Skip to content

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

Open
@snorwin

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}]

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