-
Notifications
You must be signed in to change notification settings - Fork 412
Introduced ignore attribute to JsonKey. When set to true the generato… #118
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
Introduced ignore attribute to JsonKey. When set to true the generato… #118
Conversation
…r excludes the field. Refactored _writeFactory to return the fields that were used to set, including final fields set in the constructor parameter list but excluding other final fields. Added test "works to ignore a field" Added test 'includes final field in toJson when set in ctor' which ensures the final field 'a' that is set in the constructor is included in the factory and in toJson. Added test 'excludes final field in toJson when not set in ctor' which ensures that the same field is excluded in factory and toJson if it isn't set in the constructor.
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.
Add a changelog entry to json_serializable
for this.
Check the error if a ctor references a field that's ignored.
Also add an example to the integration test
diff --git a/json_serializable/test/test_files/json_test_example.dart b/json_serializable/test/test_files/json_test_example.dart
index 2a82b8b..06356cc 100644
--- a/json_serializable/test/test_files/json_test_example.dart
+++ b/json_serializable/test/test_files/json_test_example.dart
@@ -49,6 +49,12 @@ class Order extends Object with _$OrderSerializerMixin {
Platform platform;
Map<String, Platform> altPlatforms;
+ String get platformValue => platform?.description;
+
+ set platformValue(String value) {
+ throw 'not impld';
+ }
+
int get price => items.fold(0, (total, item) => item.price + total);
Order(this.category, [Iterable<Item> items])
@@ -65,10 +65,16 @@ class JsonKey { | |||
/// enclosing class. | |||
final bool includeIfNull; | |||
|
|||
/// `true` if the generator should ignore this field completely |
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.
Add a .
at the end of the sentence.
@@ -65,10 +65,16 @@ class JsonKey { | |||
/// enclosing class. | |||
final bool includeIfNull; | |||
|
|||
/// `true` if the generator should ignore this field completely | |||
/// | |||
/// If `null` or `false`, the generator includes the field if it is not |
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.
If `null` (the default) or `false`, the field will be considered for serialization.
@@ -65,10 +65,16 @@ class JsonKey { | |||
/// enclosing class. |
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.
Also: bump the minor version of json_annotation
in the pubspec to 0.2.3-dev
.
Add an entry to the changelog (under 0.2.3
) that includes this change.
… if private field is referenced by ctor' to ensure the right error is thrown if a private or ignored field is used as a required ctor argument.
…st input class PrivateFieldCtorClass.
What should I do with this hint from travis It's caused by an update of Dart 2 and I can't find info how to replace it. |
Rebase on this branch and you'll be good - https://github.com/dart-lang/json_serializable/tree/exclude_analyzer_alpha |
…r excludes the field. Refactored _writeFactory to return the fields that were used to set, including final fields set in the constructor parameter list but excluding other final fields. Added test "works to ignore a field" Added test 'includes final field in toJson when set in ctor' which ensures the final field 'a' that is set in the constructor is included in the factory and in toJson. Added test 'excludes final field in toJson when not set in ctor' which ensures that the same field is excluded in factory and toJson if it isn't set in the constructor.
… if private field is referenced by ctor' to ensure the right error is thrown if a private or ignored field is used as a required ctor argument.
…st input class PrivateFieldCtorClass.
…github.com/AlexanderJohr/json_serializable into ignore-private-and-ignore-annotated-fields
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.
Awesome!
Yes! Thank you for your reviews and your approval! |
Hello Kevin Moore, from all the serialization libraries for dart out there, yours was always my favorite. But for me, it was a major feature: an ignore annotation.
This pull request is for the ignore attribute for JsonKey. When set to true the generator excludes the field.
What is also does is: