Room.fromJson constructor

Room.fromJson(
  1. Map<String, dynamic> dataMap
)

Creates a Room object from the JSON response to a GET request.

Implementation

factory Room.fromJson(Map<String, dynamic> dataMap) {
  // Handle entire response given with no filter.
  Map<String, dynamic> data = MiscTools.extractData(dataMap);

  return Room(
    type: ResourceType.fromString(data[ApiFields.type] ?? ""),
    id: data[ApiFields.id] ?? "",
    idV1: data[ApiFields.idV1] ?? "",
    children: (data[ApiFields.children] as List<dynamic>?)
            ?.map((child) => Relative.fromJson(child))
            .toList() ??
        [],
    services: (data[ApiFields.services] as List<dynamic>?)
            ?.map((service) => Relative.fromJson(service))
            .toList() ??
        [],
    metadata: RoomMetadata.fromJson(
      Map<String, dynamic>.from(
        data[ApiFields.metadata] ?? {},
      ),
    ),
  );
}