json_serializable.dart
json_serializable.dart copied to clipboard
Type casting ignores NNBD
Consider the code below
@JsonSerializable()
class Example {
@JsonKey(nullable: true)
List<String>? val;
const Example(this.val);
<boilerplate>
}
the generated fromJson method will look like
return Example((json['val'] as List)?.map(e => e as String)?.toList())
This currently results in a warning by dart analyzer since we're casting json['val'] to a non-null type List so the null-aware access operator isn't necessary. In this case though a more appropriate cast might be as List?.
We're a way off from making this package ready for "null safety" (previously known as NNDB)