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+
16## 4.0.1
27
38- Allow latest ` package:analyzer ` .
Original file line number Diff line number Diff line change @@ -43,10 +43,12 @@ String asStatement(DartType type) {
4343 return '' ;
4444 }
4545
46+ final nullableSuffix = type.isNullableType ? '?' : '' ;
47+
4648 if (coreIterableTypeChecker.isAssignableFromType (type)) {
4749 final itemType = coreIterableGenericType (type);
4850 if (isLikeDynamic (itemType)) {
49- return ' as List' ;
51+ return ' as List$ nullableSuffix ' ;
5052 }
5153 }
5254
@@ -55,7 +57,7 @@ String asStatement(DartType type) {
5557 assert (args.length == 2 );
5658
5759 if (args.every (isLikeDynamic)) {
58- return ' as Map' ;
60+ return ' as Map$ nullableSuffix ' ;
5961 }
6062 }
6163
Original file line number Diff line number Diff line change 11name : json_serializable
2- version : 4.0.1
2+ version : 4.0.2
33description : >-
44 Automatically generate code for converting to and from JSON by annotating
55 Dart classes.
6- repository : https://github.com/google/json_serializable.dart
6+ repository : https://github.com/google/json_serializable.dart/tree/master/json_serializable
77environment :
88 # Keeping this <2.12.0 because the code is not null safe – yet!
99 sdk : ' >=2.11.99 <3.0.0'
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ const _expectedAnnotatedTests = {
4747 'FinalFields' ,
4848 'FinalFieldsNotSetInCtor' ,
4949 'FromDynamicCollection' ,
50+ 'FromNullableDynamicCollection' ,
5051 'GeneralTestClass1' ,
5152 'GeneralTestClass2' ,
5253 'GenericArgumentFactoriesFlagWithoutGenericType' ,
Original file line number Diff line number Diff line change @@ -170,6 +170,35 @@ class FromDynamicCollection {
170170 late String iterableField;
171171}
172172
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+
173202String _noArgs () => throw UnimplementedError ();
174203
175204@ShouldThrow (
You can’t perform that action at this time.
0 commit comments