fromMap method

DataSet fromMap(
  1. Map<String, Object?>? map
)

Read DataSet from the Map which has Record and RecordList expressed in Map format.

Record and RecordList in Map format are flexible to increase or decrease the number of fields when interacting with the other party. Instead, in RecordList, the larger the number of data, the more redundant the field name output becomes, so the output size becomes huge.

For exmaple

{
  "User":{
    "header":{
      "":{
        "name":"hoge",
        "age":20,
        "hasSpouse":false
      }
    },
    "recordList":{
      "career":[
        {
          "title":"career1",
          "from":"2020/01/01",
          "to":"2020/01/30",
          "detail":["detail1","detail2"]
        },
        {
          "title":"career2",
          "from":"2020/02/01",
          "to":"2020/04/30",
          "detail":["detail1","detail2"]
        }
      ]
     }
   }
 }

Implementation

DataSet fromMap(Map<String,Object?>? map){
  if(map == null){
    return this;
  }
  MapEntry dsEntry = map.entries.first;
  if(name == null){
    name = dsEntry.key;
  }
  Map<String?,Object?>? dsMap = dsEntry.value;
  if(dsMap == null){
    return this;
  }
  Map<String?,Object?>? headers = dsMap["header"] as Map<String?,Object?>?;
  if(headers != null){
    headers.forEach(
      (name, value){
        Record? header = _headers[name?.length == 0 ? null : name];
        if(header != null && value != null){
          header.fromMap(value as Map<String,Object?>);
        }
      }
    );
  }
  Map<String?,Object?>? recordLists = dsMap["recordList"] as Map<String?,Object?>?;
  if(recordLists != null){
    recordLists.forEach(
      (name, value){
        RecordList? list = _recordLists[name?.length == 0 ? null : name];
        if(list != null && value != null){
          if(value is List){
            list.fromMap(value);
          }else if(value is Map){
            list.fromMapByMap(value);
          }
        }
      }
    );
  }
  return this;
}