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

YAML: deserialize String last in a union type #7938

Merged
merged 2 commits into from Jun 29, 2019

Conversation

@asterite
Copy link
Member

commented Jun 29, 2019

Fixes #7936

I can hear @straight-shoota's voice saying "Told ya!" but this fix is good because:

  • When mapping to a String it will always work
  • When mapping a union which has a String, String is tried last, so numbers, nulls and anything else will have precedence
@bcardiff

This comment has been minimized.

Copy link
Member

commented Jun 29, 2019

It seems there are no specs for empty values. From the null specs i guess they are not interpreted as nil, which is good. But can a spec be added to ensure that?

Otherwise LGTM

@asterite

This comment has been minimized.

Copy link
Member Author

commented Jun 29, 2019

@bcardiff I just added specs for that:

String.from_yaml("") # => ""
Nil.from_yaml("") # => nil

So in the case of a union of String | Nil, empty means null. I'm not sure how correct is that, but it's not clear from the YAML spec.

I don't think this is too problematic. If someone needs a special logic they can always use a custom converter.

@asterite asterite added this to the 0.30.0 milestone Jun 29, 2019

@asterite asterite merged commit c943f43 into crystal-lang:master Jun 29, 2019

5 checks passed

ci/circleci: check_format Your tests passed on CircleCI!
Details
ci/circleci: test_darwin Your tests passed on CircleCI!
Details
ci/circleci: test_linux Your tests passed on CircleCI!
Details
ci/circleci: test_linux32 Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@asterite asterite deleted the asterite:bug/yaml-union-string-nil branch Jun 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.