-
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
[Annotation Only] Adding case insensitive to enum based on loading JsonEnum config #1323
base: master
Are you sure you want to change the base?
[Annotation Only] Adding case insensitive to enum based on loading JsonEnum config #1323
Conversation
this.defaultValue, | ||
this.disallowNullValue, | ||
this.fromJson, | ||
@Deprecated( | ||
'Use `includeFromJson` and `includeToJson` with a value of `false` ' | ||
'instead.', | ||
) | ||
this.ignore, | ||
this.ignore, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi this was done by dart format 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to be using a dev release of Dart 3.1 for this.
/// Specifically, both values will be lower-cased and compared. | ||
/// | ||
/// Valid only on enum fields with a compatible enum value. | ||
final bool caseInsensitive; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the option needed on both JsonEnum
and JsonKey
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@t-beckmann so it can be used both at the enum level and at the field level.
Your question did make me add tests to the original PR, so I also found an issue and fixed it, and added 3 test cases: case insensitive on enum level, case insensitive on field level, and without any case insensitive (verifying behavior is same without it).
Example from the other PR:
- On the enum: https://github.com/google/json_serializable.dart/pull/1155/files#diff-1ac6a89c51c26fa87981cde2ede9cfa268021350a1bdc2770e982feea1dcf242R9
- On the field: https://github.com/google/json_serializable.dart/pull/1155/files#diff-976667989c3ddcc9bb6d6470103769f5aa9c376f142a64c76fadb4b52f03b736R58
Part of #1155 - see details here.
This is just the annotation part of the PR.