Json_serializable.dart: Incorrect code generation for inner objects

Created on 27 Aug 2019  路  3Comments  路  Source: google/json_serializable.dart

it looks like code generator made some incorrect code for inner objects
here is an example:

https://github.com/dart-lang/json_serializable/blob/6d5948508b65d8bec873b3fc213c17c884546156/example/lib/example.g.dart#L39

as we see list puts to json directly without convertion to json array

the same for single item
https://github.com/dart-lang/json_serializable/blob/6d5948508b65d8bec873b3fc213c17c884546156/example/lib/example.g.dart#L68

it should be something like this for single

  writeNotNull(
      'documentImageSizeLimit', instance.documentImageSizeLimit?.toJson());

and this for list
writeNotNull('polygon', instance.polygon?.map((f) => f.toJson())?.toList());

Most helpful comment

explicitToJson: true fixes this, but i think that its quite incorrect and should be by default

All 3 comments

explicitToJson: true fixes this, but i think that its quite incorrect and should be by default

i have version

json_annotation: ^3.0.1
and nested object have wrong 'toJson' generation

This bug is still happening 3.3.0.

Was this page helpful?
0 / 5 - 0 ratings