decodeAny static method

Map<String, Object?> decodeAny(
  1. Object? body
)

Decodes a JSON body of type List<int> or String.

Implementation

static Map<String, Object?> decodeAny(Object? body) {
  Object? decoded;
  switch (body) {
    case List<int>():
      if (body.isEmpty) return const {};
      decoded = decode(body);
    case String():
      if (body.isEmpty) return const {};
      decoded = jsonDecode(body);
    default:
      _invalidJson(body);
  }
  return switch (decoded) {
    null => const <String, Object?>{},
    Map<String, Object?>() => decoded,
    _ => _invalidJson(decoded),
  };
}