buildJSONAuthorizationBodyJSON method
Implementation
String buildJSONAuthorizationBodyJSON(HttpRequestBody? body) {
if (body == null || body.hasNoContent) {
if (field == null || field!.isEmpty) {
return encodeJSON(authorization);
} else {
return encodeJSON({field: authorization});
}
}
var bodyJson = json.decode(body.contentAsString!);
if (field == null || field!.isEmpty) {
if (authorization is Map) {
if (bodyJson is Map) {
bodyJson.addAll(authorization);
} else {
throw StateError(
"No specified field for authorization. Can't add authorization to current body! Current body is not a Map to receive a Map authorization.");
}
} else if (authorization is List) {
if (bodyJson is List) {
bodyJson.addAll(authorization);
} else {
throw StateError(
"No specified field for authorization. Can't add authorization to current body! Current body is not a List to receive a List authorization.");
}
} else {
throw StateError(
"No specified field for authorization. Can't add authorization to current body! authorization is not a Map or List to add to any type of body.");
}
} else {
bodyJson[field] = authorization;
}
return encodeJSON(bodyJson);
}