File tree 3 files changed +19
-1
lines changed
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ class JsonHelper extends TypeHelper {
33
33
var fromJsonCtor =
34
34
classElement.constructors.firstWhere ((ce) => ce.name == 'fromJson' );
35
35
// TODO: should verify that this type is a valid JSON type...but for now...
36
- var asCastType = fromJsonCtor.parameters.single .type;
36
+ var asCastType = fromJsonCtor.parameters.first .type;
37
37
38
38
var asCast = '' ;
39
39
if (! asCastType.isDynamic && ! asCastType.isObject) {
Original file line number Diff line number Diff line change @@ -188,6 +188,13 @@ abstract class _$OrderSerializerMixin {
188
188
});
189
189
}
190
190
191
+
192
+ test ('class with fromJson() constructor with optional parameters' , () async {
193
+ var output = await runForElementNamed ('FromJsonOptionalParameters' );
194
+
195
+ expect (output, contains ('new ChildWithFromJson.fromJson' ));
196
+ });
197
+
191
198
test ('class with child json-able object' , () async {
192
199
var output = await runForElementNamed ('ParentObject' );
193
200
@@ -321,6 +328,17 @@ class FinalFields {
321
328
FinalFields(this.a);
322
329
}
323
330
331
+ @JsonSerializable()
332
+ class FromJsonOptionalParameters {
333
+ final ChildWithFromJson child;
334
+
335
+ FromJsonOptionalParameters(this.child);
336
+ }
337
+
338
+ class ChildWithFromJson {
339
+ ChildWithFromJson.fromJson(json, {initValue: false}) {}
340
+ }
341
+
324
342
@JsonSerializable()
325
343
class ParentObject {
326
344
int number;
You can’t perform that action at this time.
0 commit comments