Skip to content

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
@samber samber merged commit e2cec63 into samber:master May 25, 2025
1 check passed
@samber samber mentioned this pull request May 25, 2025
liruohrh added a commit to liruohrh/mox that referenced this pull request Aug 3, 2025
samber added a commit that referenced this pull request Aug 7, 2025
@samber
Copy link
Owner

samber commented Aug 7, 2025

hi @Kiyo5hi

Following the feedback in #72, i reverted this PR: a48e63d

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.

2 participants