I don't know if null values are serialized into a JSON string as
{ "someNullableField": null }
of if the map entry is simply omitted by the JSON string serializer when the value is null, but either way, it would be more optimal in terms of time and space to only add non-null fields to the map:
Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{
if (instance.firstName != null) 'firstName': instance.firstName,
if (instance.lastName != null) 'lastName': instance.lastName,
};
Given a serializable class with nullable fields
firstName
andlastName
:currently the code generator generates the following
toJson
method given a nullable fieldsomeNullableField
:I don't know if null values are serialized into a JSON string as
of if the map entry is simply omitted by the JSON string serializer when the value is
null
, but either way, it would be more optimal in terms of time and space to only add non-null fields to the map:Related:
1369
1340
1356