Closed
Description
Enviroment
Flutter 1.10.1-pre.41 • channel master • https://github.com/flutter/flutter.git
Framework • revision 5a3a46ada2 (9 days ago) • 2019-09-07 18:37:41 -0400
Engine • revision c9ea4dba8d
Tools • Dart 2.5.0 (build 2.5.0-dev.4.0 ec7ec4ecf7)
build_runner: ^1.6.1
json_serializable: ^3.1.0
Is there any way to slove {}
with builtin way? I had a null object returned {}
, so I had to write custom fromJson
to JsonKey
. Below code sloved my problem, but I wanna check If there is more elegant way to check for all fields.
static _bankFromJson(Map<String, dynamic> json) {
if(json['bank'] == null)
return null;
else
{
if(json['bank'] is Map)
if(json['bank'].keys.length == 0)
return null;
return CompanyBank.fromJson(json['bank'] as Map<String, dynamic>);
}
}
@JsonKey(fromJson: _bankFromJson)
CompanyBank bank;