Unverified Commit defa4bce authored by Ivan Inozemtsev's avatar Ivan Inozemtsev Committed by GitHub

Change cast in json parsing (#137708)

`jsonDecode` decodes lists as `List<Object?>`, so the cast to `List<Object>` fails at runtime in sound null safety mode.
parent 3649deb3
......@@ -51,7 +51,7 @@ class BlockHashes {
blockSize: obj['blockSize']! as int,
totalSize: obj['totalSize']! as int,
adler32: Uint32List.view(base64.decode(obj['adler32']! as String).buffer),
md5: (obj['md5']! as List<Object>).cast<String>(),
md5: (obj['md5']! as List<Object?>).cast<String>(),
fileMd5: obj['fileMd5']! as String,
);
}
......
......@@ -187,4 +187,26 @@ void main() {
expect(file.readAsStringSync(), content2);
});
});
group('BlockHashes', () {
test('json conversion works normally', () {
const String json = '''
{
"blockSize":4,
"totalSize":18,
"adler32":"7ACcAu0AoALuAKQC7wCoApQA+gA=",
"md5": [
"zB0S8R/fGt05GcI5v8AjIQ==",
"uZCZ4i/LUGFYAD+K1ZD0Wg==",
"6kbZGS8T1NJl/naWODQcNw==",
"kKh/aA2XAhR/r0HdZa3Bxg==",
"34eF7Bs/OhfoJ5+sAw0zyw=="
],
"fileMd5":"VT/gkSEdctzUEUJCxclxuQ=="
}
''';
final Map<String, Object?> decodedJson = jsonDecode(json) as Map<String, Object?>;
expect(BlockHashes.fromJson(decodedJson).toJson(), decodedJson);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment