-
Notifications
You must be signed in to change notification settings - Fork 403
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
Added createJsonKeys #1401
Added createJsonKeys #1401
Changes from all commits
d296db0
0b833fc
eef5e0f
59150cc
98fcded
316cb02
e9ff4f9
0a128a6
0987633
bd5506c
f70e589
c94920c
0134b53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'json_keys_example.g.dart'; | ||
|
||
@JsonSerializable(createJsonKeys: true, fieldRename: FieldRename.kebab) | ||
class Model { | ||
Model({ | ||
required this.firstName, | ||
required this.lastName, | ||
this.ignoredName, | ||
}); | ||
|
||
factory Model.fromJson(Map<String, Object?> json) => _$ModelFromJson(json); | ||
|
||
final String firstName; | ||
|
||
@JsonKey(name: 'LAST_NAME') | ||
final String lastName; | ||
|
||
@JsonKey(includeFromJson: false, includeToJson: false) | ||
final String? ignoredName; | ||
|
||
String get fullName => '$firstName $lastName'; | ||
|
||
Map<String, Object?> toJson() => _$ModelToJson(this); | ||
} | ||
|
||
// TODO: use this once https://github.com/dart-lang/sdk/issues/54543 is fixed | ||
typedef ModelJsonKeys = _$ModelJsonKeys; | ||
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. Smart, i like the idea 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. @ChreSyr would be really nice to have this auto generated inside |
||
|
||
// Work-around until https://github.com/dart-lang/sdk/issues/54543 is fixed | ||
Set<String> get keys => {_$ModelJsonKeys.firstName, _$ModelJsonKeys.lastName}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
This should be
4.9.0
since we're adding new features!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.
Ditto with json_serial. I'll do it. Just FYI for future.