-
Notifications
You must be signed in to change notification settings - Fork 420
Allow @JsonKey
to be used on constructor parameters
#1505
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
Open
huanghui1998hhh
wants to merge
18
commits into
google:master
Choose a base branch
from
huanghui1998hhh:master
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 all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c65862d
Enable use `@JsonKey` on constructor parameters
huanghui1998hhh d38044e
code format
huanghui1998hhh c5f2f02
Merge branch 'google:master' into master
huanghui1998hhh be9f736
Merge remote-tracking branch 'upstream/master' and resolve conflict
huanghui1998hhh 8a1a758
fix: migrate to element2 api
huanghui1998hhh 5e230c7
fix: migrate to element2 api
huanghui1998hhh 7818832
fix: migrate to element2 api
huanghui1998hhh a634f31
Merge remote-tracking branch 'upstream/master'
huanghui1998hhh 5410e8c
use `where().singleOrNull` instead of `<?>[].singleWhere(orElse: null)`
huanghui1998hhh 021a09c
Merge branch 'google:master' into master
huanghui1998hhh 44bbfde
Update json_serializable/lib/src/utils.dart
huanghui1998hhh b093e69
add warning when `JsonKey` field conflict
huanghui1998hhh 1333935
code format
huanghui1998hhh 5c12843
expand the doc for `JsonKey`
huanghui1998hhh 3d87b8b
update `CHANGELOG.md`
huanghui1998hhh 9cfb5b3
Update json_serializable/CHANGELOG.md
huanghui1998hhh 2e0d4d6
code format
huanghui1998hhh 7246cfd
Update json_serializable/pubspec.yaml
huanghui1998hhh 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 hidden or 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
## 4.9.1-wip | ||
|
||
- Require Dart 3.8 | ||
- Support `JsonKey` annotation on constructor parameters. | ||
|
||
## 4.9.0 | ||
|
||
|
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 6.11.0 | ||
|
||
- Support `JsonKey` annotation on constructor parameters. | ||
|
||
## 6.10.0 | ||
|
||
- Required `analyzer: ^7.4.0`. | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// @dart=3.8 | ||
|
||
part of '_json_serializable_test_input.dart'; | ||
|
||
// https://github.com/google/json_serializable.dart/issues/1437 | ||
@ShouldGenerate( | ||
r''' | ||
CtorParamJsonKey _$CtorParamJsonKeyFromJson(Map<String, dynamic> json) => | ||
CtorParamJsonKey( | ||
attributeOne: json['first'] as String, | ||
attributeTwo: json['second'] as String, | ||
); | ||
|
||
Map<String, dynamic> _$CtorParamJsonKeyToJson(CtorParamJsonKey instance) => | ||
<String, dynamic>{ | ||
'first': instance.attributeOne, | ||
'second': instance.attributeTwo, | ||
}; | ||
''', | ||
expectedLogItems: [ | ||
huanghui1998hhh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'Field `attributeOne` has conflicting `JsonKey.name` annotations: both ' | ||
'constructor parameter and class field have this annotation. Using ' | ||
'constructor parameter value.', | ||
], | ||
) | ||
@JsonSerializable() | ||
class CtorParamJsonKey { | ||
CtorParamJsonKey({ | ||
@JsonKey(name: 'first') required this.attributeOne, | ||
@JsonKey(name: 'second') required this.attributeTwo, | ||
}); | ||
|
||
@JsonKey(name: 'fake_first') | ||
huanghui1998hhh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final String attributeOne; | ||
final String attributeTwo; | ||
} | ||
|
||
@ShouldGenerate(r''' | ||
CtorParamJsonKeyWithExtends _$CtorParamJsonKeyWithExtendsFromJson( | ||
Map<String, dynamic> json, | ||
) => CtorParamJsonKeyWithExtends( | ||
attributeOne: json['fake_first'] as String, | ||
attributeTwo: json['two'] as String, | ||
); | ||
|
||
Map<String, dynamic> _$CtorParamJsonKeyWithExtendsToJson( | ||
CtorParamJsonKeyWithExtends instance, | ||
) => <String, dynamic>{ | ||
'fake_first': instance.attributeOne, | ||
'two': instance.attributeTwo, | ||
}; | ||
''') | ||
@JsonSerializable() | ||
class CtorParamJsonKeyWithExtends extends CtorParamJsonKey { | ||
CtorParamJsonKeyWithExtends({ | ||
required super.attributeOne, | ||
@JsonKey(name: 'two') required super.attributeTwo, | ||
}); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.