From b92ad19b4597f00885a8fc53d2edd63d378ef920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20G=C3=BCltekir?= Date: Fri, 7 Jun 2024 15:18:46 +0300 Subject: [PATCH 1/2] Added list json control into the TypeRegistry fromJson method. --- lib/src/impl/type_registry.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/impl/type_registry.dart b/lib/src/impl/type_registry.dart index c8e0d7e8b..74e110d3d 100644 --- a/lib/src/impl/type_registry.dart +++ b/lib/src/impl/type_registry.dart @@ -33,6 +33,8 @@ class _TypeRegistry { } if (json is Map) { value = handler.fromJson(json); + } else if (json is List>) { + value = json.map(handler.fromJson).toList(); } else { throw ArgumentError('Type mismatch. Expected Map ' 'but got ${json.runtimeType}.'); From 782e43dacb54639abf0f58dd086ecbae8e4f39cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20G=C3=BCltekir?= Date: Fri, 7 Jun 2024 19:20:32 +0300 Subject: [PATCH 2/2] fromJson method parameters value changed with dynamic --- lib/src/impl/type_registry.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/src/impl/type_registry.dart b/lib/src/impl/type_registry.dart index 74e110d3d..44bf0bc57 100644 --- a/lib/src/impl/type_registry.dart +++ b/lib/src/impl/type_registry.dart @@ -31,10 +31,8 @@ class _TypeRegistry { 'Type is not registered. Did you forget to register it?', ); } - if (json is Map) { + if (json is Map || json is List) { value = handler.fromJson(json); - } else if (json is List>) { - value = json.map(handler.fromJson).toList(); } else { throw ArgumentError('Type mismatch. Expected Map ' 'but got ${json.runtimeType}.'); @@ -74,7 +72,7 @@ class _TypeRegistry { } } -T? _noop(Map json) { +T? _noop(dynamic json) { throw UnimplementedError(); } @@ -87,7 +85,7 @@ class _TypeHandler { final int? typeId; - final T? Function(Map json) fromJson; + final T? Function(dynamic json) fromJson; bool handlesValue(dynamic value) { return value is T;