-
Notifications
You must be signed in to change notification settings - Fork 412
Finish implementation of defaultValue #191
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
d6b6b4c
to
03fa181
Compare
part 'default_value.g.dart'; | ||
|
||
const _intValue = 42; | ||
|
||
dvi.DefaultValue fromJson(Map<String, dynamic> json) => |
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: move to factory (just for best practices)? Generally you don't want to expose a top level method with such a generic name.
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 do it so this code is easier – I want something I can tear off and I can't tear off a ctor
|
||
@JsonSerializable() | ||
class DefaultWithNestedEnum { | ||
@JsonKey(defaultValue: [Enum.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.
nit: don't you still need the const
here?
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.
you do if you want the code to run in a Dart 1 VM
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.
Tests pass fine in w/ our current setup @ latest Dart VM...
/// Helper class used in generated code with `enum` values. | ||
/// | ||
/// Should not be used directly. | ||
T $enumDecode<T>(String enumName, List<T> values, String enumValue) => |
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: for both of these methods please describe the parameters in the comment, it isn't super clear what they represent? Or possibly just rename enumValue
to serializedValue
?
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 don't want to help users here. They are an implementation details.
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.
This is useful for any dev who wants to inspect/modify/review this code though. Private functions should still be documented if they aren't self explanatory.
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.
Fixed. PTAL
Replied to comments. PTAL @natebosch @jakemac53 |
ack
…On Tue, May 29, 2018 at 1:00 PM Jacob MacDonald ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In json_annotation/lib/src/json_serializable.dart
<#191 (comment)>
:
> @@ -133,3 +133,22 @@ class JsonKey {
this.toJson,
this.defaultValue});
}
+
+// Until enum supports parse: github.com/dart-lang/sdk/issues/33244
+/// Helper class used in generated code with `enum` values.
+///
+/// Should not be used directly.
+T $enumDecode<T>(String enumName, List<T> values, String enumValue) =>
This is useful for any dev who wants to inspect/modify/*review* this code
though. Private functions should still be documented if they aren't self
explanatory.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#191 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABCiu_NHmIXHf2jYI9SHgKVXqgRv8B5ks5t3ajAgaJpZM4UOvGm>
.
|
Implementation for `checked` option Improve error messages on unsupported types Explicitly disallow defaultValue + non-nullable field support serialization of single enum values Also added $enumDecode[Nullable] helpers to json_annotation
Implementation for
checked
optionImprove error messages on unsupported types
Explicitly disallow defaultValue + non-nullable field
support serialization of single enum values
Also added $enumDecode[Nullable] helpers to json_annotation