-
Notifications
You must be signed in to change notification settings - Fork 401
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
Add JsonKey.includeFromJson/includeToJson - allow explicit control of serialization #1256
Conversation
fb7a551
to
c7bc099
Compare
Useful, I will use it, can I have a simplify description about this new improvement on Json abilities in our codes ! |
c7bc099
to
a2a3629
Compare
Is there any reason you use this |
@ValentinVignal great question! It comes down to terseness. I believe it's easier to document and explain...at least a bit. I realize it's the same state-space. Happy to discuss further, though. |
/// super classes, sorted first by their location in the inheritance hierarchy | ||
/// (super first) and then by their location in the source file. | ||
Iterable<FieldElement> createSortedFieldSet(ClassElement element) { | ||
List<FieldElement> createSortedFieldSet(ClassElement element) { |
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.
Just a small implementation tweak...
@@ -85,28 +86,44 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { | |||
final createResult = createFactory(accessibleFields, unavailableReasons); | |||
yield createResult.output; | |||
|
|||
accessibleFieldSet = accessibleFields.entries | |||
final fieldsToUse = accessibleFields.entries |
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.
Needs to be something sortable...
for (var candidate in sortedFields.where((element) => | ||
jsonKeyFor(element).explicitYesToJson && | ||
!fieldsToUse.contains(element))) { | ||
fieldsToUse.add(candidate); |
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.
Need to add candidates BACK even if they are not used in the factory if they are forced to be used for toJSON
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.
make these comments actual comments?
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.
done!
} | ||
|
||
fieldsToUse.sort( | ||
(a, b) => sortedFields.indexOf(a).compareTo(sortedFields.indexOf(b))); |
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.
Need the fields to maintain the original source ordering
I wonder, how I am able to use these fixes? @kevmoo |
@feduke-nukem ...what do you mean? |
I am not able to find JsonKey.writeOnly and others mentoned here in the latest version of package. |
@feduke-nukem – that's because I haven't published it yet! Ha! Let me see if I can do that today |
That will be really nice 😁 |
Published! |
Thanks! |
|
||
bool get explicitYesToJson => includeToJson == true; | ||
|
||
bool get explicitNoToJson => includeFromJson == false; |
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.
Shouldn't this be includeToJson == false
?
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.
Yup! Great find! #1281
...and deprecate
JsonKey.ignore
Fixes #24
Fixes #274
Fixes #537
Fixes #569
Fixes #797
Fixes #1100
Fixes #1244