Skip to content

Release 0.2.3 #35

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 2 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/type_helpers/value_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ValueHelper extends TypeHelper {
return expression;
} else if (const TypeChecker.fromRuntime(double)
.isExactlyType(targetType)) {
return '($expression as num).toDouble()';
return '($expression as num)${nullable ? '?' : ''}.toDouble()';
} else if (simpleJsonTypeChecker.isAssignableFromType(targetType)) {
return '$expression as $targetType';
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_serializable
version: 0.2.3-dev
version: 0.2.3
author: Dart Team <misc@dartlang.org>
description: Generates utilities to aid in serializing to/from JSON.
homepage: https://github.com/dart-lang/json_serializable
Expand Down
4 changes: 3 additions & 1 deletion test/json_serializable_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ void main() {
roundTripNumber(new Numbers()
..nums = [0, 0.0]
..doubles = [0.0]
..nnDoubles = [0.0]
..ints = [0]);
});

test('support ints as doubles', () {
var value = {
'doubles': [0, 0.0]
'doubles': [0, 0.0, null],
'nnDoubles': [0, 0.0]
};

roundTripNumber(new Numbers.fromJson(value));
Expand Down
6 changes: 5 additions & 1 deletion test/test_files/json_test_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class Numbers extends Object with _$NumbersSerializerMixin {
List<num> nums;
List<double> doubles;

@JsonKey(nullable: false)
List<double> nnDoubles;

Numbers();

factory Numbers.fromJson(Map<String, dynamic> json) =>
Expand All @@ -118,5 +121,6 @@ class Numbers extends Object with _$NumbersSerializerMixin {
other is Numbers &&
_deepEquals(ints, other.ints) &&
_deepEquals(nums, other.nums) &&
_deepEquals(doubles, other.doubles);
_deepEquals(doubles, other.doubles) &&
_deepEquals(nnDoubles, other.nnDoubles);
}
13 changes: 10 additions & 3 deletions test/test_files/json_test_example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.