Device.fromJson constructor
Creates a Device object from the JSON response to a GET request.
Implementation
factory Device.fromJson(Map<String, dynamic> dataMap) {
// Handle entire response given with no filter.
Map<String, dynamic> data = MiscTools.extractData(dataMap);
return Device(
type: ResourceType.fromString(data[ApiFields.type] ?? ""),
id: data[ApiFields.id] ?? "",
idV1: data[ApiFields.idV1] ?? "",
productData: DeviceProductData.fromJson(
Map<String, dynamic>.from(data[ApiFields.productData] ?? {})),
metadata: DeviceMetadata.fromJson(
Map<String, dynamic>.from(
data[ApiFields.metadata] ?? {},
),
),
services: (data[ApiFields.services] as List<dynamic>?)
?.map((service) => Relative.fromJson(service))
.toList() ??
[],
identifyAction: Map<String, dynamic>.from(
data[ApiFields.identify] ?? {})[ApiFields.action]);
}