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

Writer produce correct top-level or in-array optional elem when custo… #73

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

jangko
Copy link
Contributor

@jangko jangko commented Jan 11, 2024

…m flavor omit optional fields

@jangko jangko merged commit 9c74b88 into master Jan 11, 2024
12 checks passed
@jangko jangko deleted the top-level-null branch January 11, 2024 10:27
test "results option array some MyJson":
var val = [Opt.some(123), Opt.some(345)]
let json = MyJson.encode(val)
check json == "[123,345]"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm, I think the semantics proposed here could be very surprising for the user. Omitting optional fields in objects in one thing, but filtering such values out of array, so the array length is effectively changed is something that feels much more dangerous.

We could have a separate policy setting that controls this aspect perhaps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't change the array length. The old code is wrong. It didn't output anything between two comma which is violating the spec. Now it works correctly by writing null to that position in the array. It's correct according to the json spec and the rpc spec.

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