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

Support omitempty option on JSON marshaling #17

Merged
merged 2 commits into from
Nov 9, 2022

Conversation

moznion
Copy link
Owner

@moznion moznion commented Nov 9, 2022

This pull request makes it support the omitempty option on JSON marshaling. If the property has that option and the value is None[T], it omits that property from serialized JSON string.

example:

type JSONStruct struct {
	OmitemptyVal Option[string] `json:"omitemptyVal,omitempty"` // this should be omitted
}
jsonStruct := &JSONStruct{OmitemptyVal: None[string]()}
marshal, err := json.Marshal(jsonStruct)
if err != nil {
	return err
}
fmt.Printf("%s\n", marshal) // => {}

Signed-off-by: moznion <moznion@mail.moznion.net>
Signed-off-by: moznion <moznion@mail.moznion.net>
@moznion moznion added the enhancement New feature or request label Nov 9, 2022
@moznion moznion self-assigned this Nov 9, 2022
@moznion moznion merged commit c8062ba into main Nov 9, 2022
@moznion moznion deleted the supporrt_ommitempty_json_marshalling branch November 9, 2022 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant