-
Notifications
You must be signed in to change notification settings - Fork 402
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
Add aliases
to JsonValue
to enum value to be decoded from different JSON values
#1459
base: master
Are you sure you want to change the base?
Conversation
Ideally we'd have a couple of tests to validate the failure cases, but I get that those can be tricky to add. |
@kevmoo What would be the failure cases for this PR? Can you give an example? |
Unsupported types in the set is the big one. |
Ah, yes, the idea is to mimic I am going to work on this test. |
You'll need to rebase this fix. |
Mmm, I had made a regular merge, but GitHub is saying to me that "this branch must not contain merge commits", so I rewrote the commits using a rebase instead, but it is still giving me this message. |
Well, the test that did not pass locally passed here, so we are good with it. |
Solves #1380.
Adds a parameter to
JsonValue
calledaliases
, which accepts a list of values that can be alternatively used to decode a JSON.Example:
With the code above, all of
200
,201
and202
would be decoded asStatusCode.success
.When calling
toJson
, however, thevalue
parameter is used. In this case,200
.Notes
$enumDecode
and$enumDecodeNullable
were not changed because they are public and there are packages that depend on them. Instead,$enumDecodeWithDecodeMap
and$enumDecodeNullableWithDecodeMap
were introduced. We may want to deprecate the former at some point and remove them in a major version.