Skip to content

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

Merged
merged 3 commits into from
May 29, 2018
Merged

Finish implementation of defaultValue #191

merged 3 commits into from
May 29, 2018

Conversation

kevmoo
Copy link
Collaborator

@kevmoo kevmoo commented May 26, 2018

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

@kevmoo kevmoo force-pushed the more_json_fun branch 3 times, most recently from d6b6b4c to 03fa181 Compare May 28, 2018 21:38
@kevmoo kevmoo changed the title WIP: more default value fun Finish implementation of defaultValue May 28, 2018
@kevmoo kevmoo requested review from natebosch and jakemac53 May 28, 2018 21:39
part 'default_value.g.dart';

const _intValue = 42;

dvi.DefaultValue fromJson(Map<String, dynamic> json) =>
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


@JsonSerializable()
class DefaultWithNestedEnum {
@JsonKey(defaultValue: [Enum.value])
Copy link
Collaborator

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?

Copy link
Member

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

Copy link
Collaborator Author

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) =>
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. PTAL

@kevmoo
Copy link
Collaborator Author

kevmoo commented May 29, 2018

Replied to comments. PTAL @natebosch @jakemac53

@kevmoo
Copy link
Collaborator Author

kevmoo commented May 29, 2018 via email

kevmoo added 2 commits May 29, 2018 13:46
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
@kevmoo kevmoo merged commit 60b29d1 into master May 29, 2018
@kevmoo kevmoo deleted the more_json_fun branch May 29, 2018 21:24
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.

3 participants