-
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
Open
matanshukry
wants to merge
14
commits into
google:master
Choose a base branch
from
matanshukry:enum-case-insensitive-annotation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b2baaad
Adding case insensitive to enum based on loading JsonEnum config
matanshukry f0cde55
cr comments
matanshukry e942e33
Merge remote-tracking branch 'origin/master' into enum-case-insensitive
matanshukry 062a779
Removing .idea files
matanshukry c548f2c
Format + removing caseInsensitive which was removed
matanshukry ac0c219
Added case insensitive as param to enum + fixed test
matanshukry affef24
Merge remote-tracking branch 'origin/master' into enum-case-insensitive
matanshukry b9c1fd5
keeping only annotation changes
matanshukry 2a702b1
Format result
matanshukry ff3ae31
Verified and added test specifically for enum key, enum json, and none
matanshukry 83dd8ab
Reformat
matanshukry 91383db
Merge branch 'enum-case-insensitive' into enum-case-insensitive-annot…
matanshukry 6cd346f
Reverting json serializable changes after merge
matanshukry b30243d
Removing build directory mistakenly added
matanshukry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andJsonKey
?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: