-
Notifications
You must be signed in to change notification settings - Fork 413
More control over which fields should be added to fromJson and toJson #1178
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
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
I guess this approach you suggested could also be used. Let me know if you want me to take a look at that. |
I think I like the enum route. Just allows us to unify more things! |
Okay, I should be able to implement this. Two questions:
Should there be a fifth option, that matches the old behaviour, to prevent those breaking changes? |
@JsonKey(includeWith: IncludeWith.fromJson) | ||
String get setter => someString; | ||
|
||
set setter(String value) => someString = value; |
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.
Since the JsonKey
annotation can't be added to setters, we still need a getter.
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.
I guess it would be possible to also support fields that only have setters? @kevmoo would you consider this PR, if I implemented this, or are there other issues with this PR or just limited time/resources from your side?
@@ -136,3 +136,5 @@ class JsonKey { | |||
} | |||
|
|||
enum _NullAsDefault { value } | |||
|
|||
enum IncludeWith { both, toJson, fromJson, ignore, legacy } |
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.
I added a fifth option, currently called legacy
. Fields that use this option should behave as fields that previously used ignore: false
. Currently this is the default option.
update fork
So. I think I like this BUT! it's a breaking change. We could bring it in as a non-breaking change, but we'd need to keep the existing Are you on Twitter ? Can you DM me so we can schedule time to chat about this? |
Latest changes from json_serializable master
I just saw that you enabled the CI. This PR was a bit of a mess. Two different approaches, only code and no explanation. I am currently preparing a new PR that addresses the |
Can't run with this. Need to have a model that support the old and the new living together. |
Adds the option to
JsonKey
to include fields intoJson
that are not used in the factory (fromJson
).Related issues: #24, #891