Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(option): fixed sematic issue in option type and adapted omitzero tag #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kiyo5hi
Copy link

@Kiyo5hi Kiyo5hi commented Feb 27, 2025

In the past, especially with the omitempty tag, there has been a semantic issue with the Option type: whether a user omitted a field or set it to null manually, isPresent would be set to false.

This introduced ambiguity similar to a raw pointer in Go since we couldn't differentiate between these two scenarios.

With the introduction of omitzero in Go 1.24, this problem can be completely resolved.

  1. When a user marshals a struct, Options with isPresent set to false are dropped, indicating "I do not want to touch this value."
  2. When a user unmarshals a struct, fields included in the JSON payload will always have isPresent set to true, indicating "I do want to touch this value."

@Kiyo5hi Kiyo5hi force-pushed the kiyoshi.guo/json-marshal branch from 70fcaa4 to a5c4278 Compare February 27, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant