CockpitRemoteBridgeRequest.fromJson constructor
Implementation
factory CockpitRemoteBridgeRequest.fromJson(Map<String, Object?> json) {
final jsonBody = json['jsonBody'];
final requestId = json['requestId'];
final method = json['method'];
final path = json['path'];
if (requestId is! String || requestId.isEmpty) {
throw const FormatException(
'Bridge request field "requestId" must be a non-empty string.',
);
}
if (method is! String || method.isEmpty) {
throw const FormatException(
'Bridge request field "method" must be a non-empty string.',
);
}
if (path is! String || path.isEmpty) {
throw const FormatException(
'Bridge request field "path" must be a non-empty string.',
);
}
if (jsonBody != null && jsonBody is! Map<Object?, Object?>) {
throw const FormatException(
'Bridge request field "jsonBody" must be a JSON object.',
);
}
return CockpitRemoteBridgeRequest(
requestId: requestId,
method: method,
path: path,
jsonBody: jsonBody == null
? null
: Map<String, Object?>.from(jsonBody as Map<Object?, Object?>),
);
}