-
Notifications
You must be signed in to change notification settings - Fork 401
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
Adding case insensitive to enum based on loading JsonEnum config #1155
base: master
Are you sure you want to change the base?
Conversation
@kevmoo ? |
Happy to look at this again. Will need a rebase! See my other comments! |
@kevmoo merged with master and fixed the comments. Please take a look again |
@matanshukry – you'll need to do a rebase and look at the analyzer errors |
I think this is headed in a good direction, though! |
Currently there are 347 issues - most of which are errors - when I analyze the master branch 😓 ( Any specific errors you want me to take a look at, that's related to this PR? |
@matanshukry – you should fix all of them. 😄 |
What 🤔 Why should I fix all of the errors that exists today in the repo? this PR is about introducing a new fix, not fixing the issues the repo already has. |
@matanshukry – we are green at HEAD - https://github.com/google/json_serializable.dart/actions/runs/4995588862 |
@kevmoo locally I still a lot of issues, even on master. I'm using dart 3.0.0 so that should be the same, but I am using windows (vs linux on the machines). You've now let the CI run so I can see the errors through that (and working on it now), but if you have a better way of checking it locally on windows that would be great 🙏 |
@matanshukry – just need to check analyzer, formatter, and run tests locally |
@kevmoo looks like the result locally are different than the CI though, at least for the analyzer. For the testing - how do you generate the .g file, specifically for |
For anyone interested: So apparently the example lib has overrides for path (I tried to just change the version without the override to path, it didn't work). I then copied the example lib (and another common file that's needed), and ran build on that directory. @kevmoo Regardless, the tests in the annotation won't succeed because it doesn't even recognize the existence of the field Hence I've created a separate PR for the annotation only: Let me know if there's another method you would like to do that. |
Just add (path) dependency overrides. You want to test EVERYTHING before you publish ANYTHING. |
Already did that locally, that's not the issue. All tests passed when I do that. I'm assuming you don't want that added to this PR though. |
@kevmoo fyi - there's no reason to run the builds until the other PR is merged and the versions are updated; it will always fail until then. |
Hi @matanshukry @kevmoo Do you plan to continue on this? 🙏 I'd love to have support for enum case insensitivity. I am open to help with finishing this PR as well. |
Fixes issue #927
Problem
Currently when parsing enum we compare thme using the equal operator. Enum values that differ only in cases (e.g. 'sunday' and 'SuNDaY') are not equal, and result in parsing error.
The user should have the possibiliy to decide on the comparator, at least in terms of case insensitive.
Solution
The solution suggested in this PR is:
caseInsensitive
flag to theJsonEnum
class.==
operator, we use a comparator function.==
operator, and a second one that assumes the value is String, and implementation check if the other object is also string and the.toLowerCase()
on both of them is equal.==
operator.$enumDecodeNullable
or$enumDecode
, we add an argumnet to use the 2nd case-insensitive operator, if thecaseInsensitive
flag exists.Improvements
Extra notes