diff --git a/lib/src/database/hive_database.dart b/lib/src/database/hive_database.dart index ca039a03..08e788a9 100644 --- a/lib/src/database/hive_database.dart +++ b/lib/src/database/hive_database.dart @@ -1053,15 +1053,25 @@ class FamedlySdkHiveDatabase extends DatabaseApi { } } +dynamic _castValue(dynamic value) { + if (value is Map) { + return convertToJson(value); + } + if (value is List) { + return value.map(_castValue).toList(); + } + return value; +} + +/// Hive always gives back an `_InternalLinkedHasMap`. This +/// creates a deep copy of the json and makes sure that the format is always +/// `Map`. Map convertToJson(Map map) { - final jsonMap = { - for (final entry in map.entries) ...{ - if (entry.value is Map) - '${entry.key.toString()}': convertToJson(entry.value), - if (!(entry.value is Map)) '${entry.key.toString()}': entry.value, - } - }; - return jsonMap; + final copy = Map.from(map); + for (final entry in copy.entries) { + copy[entry.key] = _castValue(entry.value); + } + return copy; } class MultiKey {