Skip to content

Introduced ignore attribute to JsonKey.#114

Closed
Alexander-Aue-Johr wants to merge 72 commits into
google:masterfrom
Alexander-Aue-Johr:ignore-private-and-ignore-annotated-fields
Closed

Introduced ignore attribute to JsonKey.#114
Alexander-Aue-Johr wants to merge 72 commits into
google:masterfrom
Alexander-Aue-Johr:ignore-private-and-ignore-annotated-fields

Conversation

@Alexander-Aue-Johr

@Alexander-Aue-Johr Alexander-Aue-Johr commented Mar 12, 2018

Copy link
Copy Markdown
Contributor

Hello Kevin Moore, from all the serialization libraries for dart out there, yours was always my favorite. But for me, it was lacking 2 major features: an ignore annotation and keep initial values if the deserialized field is null. I created two branches in this fork which include these features. With them, it's all I wanted from a serialization library for dart for a long time and I use it with joy already, but I want to share my joy with the community.

I want to add examples, tests, how to guides in the readme and so on. I also have to run the tests, which is difficult for me under windows, because the tools don't work so well and I'm lacking time to do it on Linux.

The reason for those pull requests is that I want to get in touch with you first and get feedback on how to change or rename certain things.

This pull request is for the ignore attribute for JsonKey. When set to true the generator excludes the field.

@JsonSerializable(includeIfNull: false, nullable: false)
class Column extends _$ColumnSerializerMixin {
// [...]
// ColumnSettings is serializable
ColumnSettings settings = new ColumnSettings();

// ColumnSettings is already serializable and includes witdh.
// Without 'ignore' the generator would generate the same field for ColumnSettings and Column 
@JsonKey(ignore: true)
num get width => settings.width;
set width (num value) =>settings.width = value;
// [...]
}

What is also does is:

  • exclude private fields
  • refactored _writeFactory to do only one thing. Extracted the part where it fetches the final fields.

What I want to know is, if you recommend:

  • to use another annotation to ignore a field instead of an ignore attribute in JsonKey, because ig ignored why call it JsonKey?
  • to reenable private fields
  • to throw an error if someone tries to use a private field in a constructor if private fields should be excluded? Your awesome library even handles deserializing into named and positioned constructor parameters (I don't know any library that doesn't complain if there isn't a parameterless default constructor.). But if the parameter assigns to a private field it must be possible to deserialize that field too.

kevmoo and others added 30 commits November 2, 2017 16:03
...and ensure pubspec/readme consistency with a test
We always want this code to be usable outside the repo since it's
referenced directly.
* Added a new method: jsonPartBuilder - so folks don't need to reference
  source_gen

* Deprecated generators.dart in favor of json_serializable.dart
@googlebot

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@kevmoo kevmoo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to add a dependency_override on json_serializable to `get the latest annotation

dependency_overrides:
  json_annotation:
    path: ../json_annotation


/// Returns the set of fields that are not written to via constructors.
Set<FieldElement> _writeFactory(
_writeFactory(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to void

@kevmoo

kevmoo commented Mar 12, 2018

Copy link
Copy Markdown
Collaborator

Please add tests for this as well – even just changing one of the examples in in test/ to use this key to show how it works...

@Alexander-Aue-Johr

Copy link
Copy Markdown
Contributor Author

Ok, I will run the tests soon on a non-windows machine soon and fix them and also add new ones for the ignore feature.

But apart from that, do you have feedback for me regarding my questions at the end of my pull request comment?

@kevmoo

kevmoo commented Mar 13, 2018

Copy link
Copy Markdown
Collaborator

Looking better – check out this guy - https://travis-ci.org/dart-lang/json_serializable/jobs/352621359#L561

@kevmoo

kevmoo commented Mar 16, 2018

Copy link
Copy Markdown
Collaborator

@AlexanderJohr ?

@Alexander-Aue-Johr

Copy link
Copy Markdown
Contributor Author

@kevmoo Yes, looking into it this weekend!

kevmoo and others added 6 commits March 16, 2018 13:26
…including final fields set in the constructor parameter list but excluding other final fields.
…sures 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.
@Alexander-Aue-Johr

Copy link
Copy Markdown
Contributor Author

I fixed the bugs and made the tests run green.
I also added a test showing the usage of the ignore field and two more tests to ensure final fields are included when set in constructor and excluded when not.

@Alexander-Aue-Johr

Copy link
Copy Markdown
Contributor Author

Sorry, I oversaw that dartfmt needs to be run on that one file.

@googlebot

Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@Alexander-Aue-Johr

Copy link
Copy Markdown
Contributor Author

I had to rewrite the git history because I committed on different systems with different email addresses without noticing. I thought this would remove the CLA waring but it seems that it made it worse. Should I just fork again, apply the changes and create a new Pull Request with the same Github user?

@kevmoo

kevmoo commented Mar 21, 2018

Copy link
Copy Markdown
Collaborator

Should I just fork again, apply the changes and create a new Pull Request with the same Github user?

That's fine!

@Alexander-Aue-Johr

Copy link
Copy Markdown
Contributor Author

Created new Pull Request with CLA signed commit authors: #118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants