File tree Expand file tree Collapse file tree 5 files changed +41
-4
lines changed Expand file tree Collapse file tree 5 files changed +41
-4
lines changed Original file line number Diff line number Diff line change
1
+ ## 4.0.2
2
+
3
+ - Correctly handle nullable ` Map ` and ` Iterable ` JSON types exposed by both
4
+ class- and function-based converters.
5
+
1
6
## 4.0.1
2
7
3
8
- Allow latest ` package:analyzer ` .
Original file line number Diff line number Diff line change @@ -43,10 +43,12 @@ String asStatement(DartType type) {
43
43
return '' ;
44
44
}
45
45
46
+ final nullableSuffix = type.isNullableType ? '?' : '' ;
47
+
46
48
if (coreIterableTypeChecker.isAssignableFromType (type)) {
47
49
final itemType = coreIterableGenericType (type);
48
50
if (isLikeDynamic (itemType)) {
49
- return ' as List' ;
51
+ return ' as List$ nullableSuffix ' ;
50
52
}
51
53
}
52
54
@@ -55,7 +57,7 @@ String asStatement(DartType type) {
55
57
assert (args.length == 2 );
56
58
57
59
if (args.every (isLikeDynamic)) {
58
- return ' as Map' ;
60
+ return ' as Map$ nullableSuffix ' ;
59
61
}
60
62
}
61
63
Original file line number Diff line number Diff line change 1
1
name : json_serializable
2
- version : 4.0.1
2
+ version : 4.0.2
3
3
description : >-
4
4
Automatically generate code for converting to and from JSON by annotating
5
5
Dart classes.
6
- repository : https://github.com/google/json_serializable.dart
6
+ repository : https://github.com/google/json_serializable.dart/tree/master/json_serializable
7
7
environment :
8
8
# Keeping this <2.12.0 because the code is not null safe – yet!
9
9
sdk : ' >=2.11.99 <3.0.0'
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ const _expectedAnnotatedTests = {
47
47
'FinalFields' ,
48
48
'FinalFieldsNotSetInCtor' ,
49
49
'FromDynamicCollection' ,
50
+ 'FromNullableDynamicCollection' ,
50
51
'GeneralTestClass1' ,
51
52
'GeneralTestClass2' ,
52
53
'GenericArgumentFactoriesFlagWithoutGenericType' ,
Original file line number Diff line number Diff line change @@ -170,6 +170,35 @@ class FromDynamicCollection {
170
170
late String iterableField;
171
171
}
172
172
173
+ String _fromNullableDynamicMap (Map ? input) => '' ;
174
+
175
+ String _fromNullableDynamicList (List ? input) => 'null' ;
176
+
177
+ String _fromNullableDynamicIterable (Iterable ? input) => 'null' ;
178
+
179
+ @ShouldGenerate (
180
+ r'''
181
+ FromNullableDynamicCollection _$FromNullableDynamicCollectionFromJson(
182
+ Map<String, dynamic> json) {
183
+ return FromNullableDynamicCollection()
184
+ ..mapField = _fromNullableDynamicMap(json['mapField'] as Map?)
185
+ ..listField = _fromNullableDynamicList(json['listField'] as List?)
186
+ ..iterableField =
187
+ _fromNullableDynamicIterable(json['iterableField'] as List?);
188
+ }
189
+ ''' ,
190
+ configurations: ['default' ],
191
+ )
192
+ @JsonSerializable (createToJson: false )
193
+ class FromNullableDynamicCollection {
194
+ @JsonKey (fromJson: _fromNullableDynamicMap)
195
+ late String mapField;
196
+ @JsonKey (fromJson: _fromNullableDynamicList)
197
+ late String listField;
198
+ @JsonKey (fromJson: _fromNullableDynamicIterable)
199
+ late String iterableField;
200
+ }
201
+
173
202
String _noArgs () => throw UnimplementedError ();
174
203
175
204
@ShouldThrow (
You can’t perform that action at this time.
0 commit comments