Skip to content

Commit

Permalink
Resolve problem in main_json_serializable example (lejard-h#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibadin authored Apr 24, 2022
1 parent dbf4272 commit 976d457
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions example/bin/main_json_serializable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ Future<Request> authHeader(Request request) async => applyHeader(
"42",
);

typedef T JsonFactory<T>(Map<String, dynamic> json);
typedef JsonFactory<T> = T Function(Map<String, dynamic> json);

class JsonSerializableConverter extends JsonConverter {
final Map<Type, JsonFactory> factories;

JsonSerializableConverter(this.factories);
const JsonSerializableConverter(this.factories);

T? _decodeMap<T>(Map<String, dynamic> values) {
/// Get jsonFactory using Type parameters
Expand All @@ -82,10 +82,10 @@ class JsonSerializableConverter extends JsonConverter {
List<T> _decodeList<T>(Iterable values) =>
values.where((v) => v != null).map<T>((v) => _decode<T>(v)).toList();

dynamic _decode<T>(dynamic entity) {
if (entity is Iterable) return _decodeList<T>(entity);
dynamic _decode<T>(entity) {
if (entity is Iterable) return _decodeList<T>(entity as List);

if (entity is Map<String, dynamic>) return _decodeMap<T>(entity);
if (entity is Map) return _decodeMap<T>(entity as Map<String, dynamic>);

return entity;
}
Expand Down

0 comments on commit 976d457

Please sign in to comment.