Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
snorwin opened this issue Mar 28, 2021 · 0 comments
Assignees
Labels
bug Something isn't working v2

Comments

@snorwin
Copy link
Owner

snorwin commented Mar 28, 2021

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}]
@snorwin snorwin added the bug Something isn't working label Mar 28, 2021
@snorwin snorwin self-assigned this Mar 28, 2021
@snorwin snorwin changed the title omitempty in combination with zero values and empty slices/maps is creating patches as expected omitempty in combination with zero values and empty slices/maps isn't creating patches as expected May 19, 2021
@snorwin snorwin added the v2 label Apr 17, 2024
@snorwin snorwin changed the title omitempty in combination with zero values and empty slices/maps isn't creating patches as expected omitempty in combination with zero values and empty slices/maps isn't creating patches as expected Apr 17, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working v2
Projects
None yet
Development

No branches or pull requests

1 participant