toMap method
Output the value of this record to the Map
If hasNull
is set to false, fields with a value of null will not be output. this can be used to reduce the output when there is no need to tell that they are null.
If toJsonType
is set to true, fields of unsuitable JSON types will be attempted to be converted to String.
Implementation
Map<String,Object?> toMap({bool hasNull=true, bool toJsonType=false}){
Map<String,Object?> map = Map();
if(_schema != null){
for(FieldSchema field in _schema!.fields){
if(!field.isOutput){
continue;
}
Object? value = _getValue(field, toJsonType);
if(!hasNull && value == null){
continue;
}
if(value != null){
if(field.isRecord){
value = (value as Record).toMap(hasNull : hasNull, toJsonType:toJsonType);
}else if(field.isRecordList){
value = (value as RecordList).toMap(hasNull : hasNull, toJsonType:toJsonType);
}
}
map[field.name] = value;
}
}
return map;
}