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

cm: implement JSON [un]marshaling for Option types #301

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

brooksmtownsend
Copy link

  • cm: implement JSON [un]marshaling for Option types
  • cm: test JSON [un]marshaling for Option types

This PR implements (naively) option marshaling/unmarshaling for Option types. This case is fairly straightforward, marshal to null if None and to the value if present.

Opening this as a draft just to ensure that this is a change that's well received that follows contribution structure, open to changing anything here!

Addresses Option un/marshaling for #239

@brooksmtownsend brooksmtownsend requested a review from ydnar as a code owner March 7, 2025 17:27
@brooksmtownsend brooksmtownsend marked this pull request as draft March 7, 2025 17:27
Copy link
Collaborator

@ydnar ydnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This seems roughly right, but how would option<option> serialize and deserialize symmetrically?

@@ -57,3 +59,25 @@ func (o option[T]) Value() T {
}
return o.some
}

// MarshalJSON implements the json.Marshaler interface.
func (o Option[T]) MarshalJSON() ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods should be on option[T] so named option types inherit the methods.

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