-
Couldn't load subscription status.
- Fork 435
[Annotation Only] Adding case insensitive to enum based on loading JsonEnum config #1323
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
base: master
Are you sure you want to change the base?
Changes from all commits
b2baaad
f0cde55
e942e33
062a779
c548f2c
ac0c219
affef24
b9c1fd5
2a702b1
ff3ae31
83dd8ab
91383db
6cd346f
b30243d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,19 +149,26 @@ class JsonKey { | |
| /// valid on a nullable enum field. | ||
| final Enum? unknownEnumValue; | ||
|
|
||
| /// If true, enum will be parsed with case-insensitive. | ||
| /// Specifically, both values will be lower-cased and compared. | ||
| /// | ||
| /// Valid only on enum fields with a compatible enum value. | ||
| final bool caseInsensitive; | ||
|
|
||
| /// Creates a new [JsonKey] instance. | ||
| /// | ||
| /// Only required when the default behavior is not desired. | ||
| const JsonKey({ | ||
| @Deprecated('Has no effect') bool? nullable, | ||
| @Deprecated('Has no effect') | ||
| bool? nullable, | ||
| 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 commentThe 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 commentThe 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. |
||
| this.includeFromJson, | ||
| this.includeIfNull, | ||
| this.includeToJson, | ||
|
|
@@ -170,6 +177,7 @@ class JsonKey { | |
| this.required, | ||
| this.toJson, | ||
| this.unknownEnumValue, | ||
| this.caseInsensitive = false, | ||
| }); | ||
|
|
||
| /// Sentinel value for use with [unknownEnumValue]. | ||
|
|
||
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
JsonEnumandJsonKey?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: