Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add JsonSerializable(createJsonMeta) (#1164)
As discussed before, this adds an option for generating a constant Map of property name: json name fixes #972
- Loading branch information
1 parent
0f383e7
commit 25c6138
Showing
17 changed files
with
161 additions
and
39 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'field_map_example.g.dart'; | ||
|
||
@JsonSerializable(createFieldMap: 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(ignore: true) | ||
final String? ignoredName; | ||
|
||
String get fullName => '$firstName $lastName'; | ||
|
||
Map<String, Object?> toJson() => _$ModelToJson(this); | ||
} | ||
|
||
const modelFieldMap = _$ModelFieldMap; | ||
|
||
@JsonSerializable( | ||
createFieldMap: true, | ||
fieldRename: FieldRename.kebab, | ||
createFactory: false, | ||
) | ||
class _PrivateModel { | ||
_PrivateModel(this.fullName); | ||
|
||
final String fullName; | ||
|
||
Map<String, Object?> toJson() => _$PrivateModelToJson(this); | ||
} | ||
|
||
const privateModelFieldMap = _$PrivateModelFieldMap; |
33 changes: 33 additions & 0 deletions
33
json_serializable/test/integration/field_map_example.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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