-
Notifications
You must be signed in to change notification settings - Fork 412
Add option for implicitToJson
#195
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
CC @jmrboosties – let me know if this makes sense... |
Looks great! Thanks a lot. |
I'm not sure about the naming... I don't think this is about "explicit" vs "implicit". Maybe something like Also, is there any reason not do do this by default? |
I was thinking that the call to
I pondered making this I think it makes the behavior a bit more clear... |
@@ -21,11 +21,15 @@ class JsonHelper extends TypeHelper { | |||
/// By default, JSON encoding in from `dart:convert` calls `toJson()` on |
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.
nit: update this comment
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.
how?
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.
By noting that if context.explicitToJson
is true
these calls will be injected automatically.
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
|
||
@JsonSerializable(createFactory: false) | ||
class TrivialNestedNullable { | ||
TrivialNestedNullable child; |
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.
consider adding an int
or some other non-custom type here, we want to make sure we don't call toJson
on those
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.
sure...the code paths for this are so crazy independent, I'm not too worried – but paranoia is good!
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.
It also prevents future regressions etc, looking at this PR alone its not clear this has the correct behavior today.
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
@jakemac53 thoughts on changing the flag name/default? We could do with |
I like I actually ran into this with the firebase package if I recall... I think it doesn't use the built in json encode/decode functionality. I would also be fine with |
Allows users to opt-in to including `.toJson()` calls on nested objects in generated `toJson` methods. This is useful if you want to round-trip the output of toJson without putting it through jsonEncode and jsonDecode Fixes #192
f31db59
to
be7394b
Compare
Name/default flipped. PTAL @jakemac53 @natebosch |
I still don't think "implicit" vs "explicit" is the distinction this is making. This is about an output which is only compatible with |
I think the name is not super important. It'll be rarely used – just need to make sure it's documented. I'm okay with |
What about |
The other option is to skip the option, make it always on, and do the breaking version bump with this change. This package has a lot of configuration options already and it might not hurt to reduce the surface area a bit. |
|
Going to hold off on this PR for a bit... |
Allows users to opt-in to including
.toJson()
calls on nestedobjects in generated
toJson
methods.This is useful if you want to round-trip the output of toJson without
putting it through jsonEncode and jsonDecode
Fixes #192