toMap method

Map<String, Object> toMap({
  1. bool hasNull = true,
  2. bool isOutputSchema = false,
  3. bool toJsonType = false,
})

Outputs a map with Record and RecordList expressed in Map format.

If hasNull is set to false, fields with a value of null will not be printed; this can be used to reduce the output when there is no need to tell that they are null. If isOutputSchema is set to true, the schema information is output. You can specify this if you don't want to share the schema with the other party, but you don't need to specify this in general. 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 isOutputSchema=false, bool toJsonType=false}){
  Map<String,Object> map = Map();
  if(isOutputSchema){
    map["schema"] = _toSchemaMap(toJsonType);
  }
  if(_headers.isNotEmpty){
    Map<String?,Object> headerMap = new Map();
    map["header"] = headerMap;
    _headers.forEach(
      (name, value){
        headerMap[name == null && toJsonType ? "" : name] = value.toMap(hasNull:hasNull,toJsonType:toJsonType);
      }
    );
  }
  if(_recordLists.isNotEmpty){
    Map<String?,Object> recordListMap = new Map();
    map["recordList"] = recordListMap;
    _recordLists.forEach(
      (name, value){
        recordListMap[name == null && toJsonType ? "" : name] = value.toMap(hasNull:hasNull,toJsonType:toJsonType);
      }
    );
  }
  Map<String,Object> dsMap = Map();
  dsMap[name == null ? "" : name!] = map;
  return dsMap;
}