toList method

Map<String, Object> toList(
  1. {bool hasNull = true,
  2. bool isOutputSchema = false,
  3. bool toJsonType = false,
  4. bool isListHeader = true,
  5. bool isListRecordList = true}
)

Outputs a map with Record and RecordList expressed in List 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. It is specified to compensate for the weaknesses of the List format, which is vulnerable to increasing or decreasing fields or not sharing a schema with an opponent. If toJsonType is set to true, fields of unsuitable JSON types will be attempted to be converted to String. If isListHeader is set to false, the output format of Header is set to Map format. If isListRecordList is set to false, the output format of RecordList is set to Map format.

Implementation

Map<String,Object> toList(
  {
    bool hasNull=true,
    bool isOutputSchema=false,
    bool toJsonType=false,
    bool isListHeader:true,
    bool isListRecordList:true
  }
){
  Map map = Map<String,Object>();
  if(isOutputSchema){
    map["schema"] = _toSchemaMap(toJsonType);
  }
  if(_headers.isNotEmpty){
    Map<String?,Object> headerMap = new Map();
    map["header"] = headerMap;
    _headers.forEach(
      (name, value){
        if(toJsonType && name == null){
          name = "";
        }
        if(isListHeader){
          headerMap[name] = value.toList(toJsonType:toJsonType);
        }else{
          headerMap[name] = value.toMap(hasNull:hasNull,toJsonType:toJsonType);
        }
      }
    );
  }
  if(_recordLists.isNotEmpty){
    Map<String?,Object> recordListMap = new Map();
    map["recordList"] = recordListMap;
    _recordLists.forEach(
      (name, value){
        if(toJsonType && name == null){
          name = "";
        }
        if(isListRecordList){
          recordListMap[name] = value.toDeepList(toJsonType:toJsonType);
        }else{
          recordListMap[name] = value.toMap(hasNull:hasNull,toJsonType:toJsonType);
        }
      }
    );
  }
  Map<String,Object> dsMap = Map();
  dsMap[name == null ? "" : name!] = map;
  return dsMap;
}