dart-json-mapper
dart-json-mapper copied to clipboard
Error with generic type
Hello,
I have these Dart class:
@jsonSerializable
class PageImpl<T>
{
List<T>? content;
PageRequest? pageable;
bool? empty;
bool? first;
bool? last;
int? number;
int? numberOfElements;
int? size;
Sort? sort;
int? totalElements;
int? totalPages;
}
@jsonSerializable
class Advertising extends AbstractEntity
{
String? title;
double? price;
int? quantity;
String? description;
AdvertisingCondition? condition;
AdvertisingStatus? status;
List<String>? images;
List<String>? sourceImages;
String? sourceId;
String? sourceUrl;
Store? store;
Product? product;
}
When I try to deserialize this sample json:
{
"content":[
{
"id":25438,
"created":"2024-07-04T18:46:31.048683Z",
"updated":"2024-07-04T20:45:00.030320Z",
"title":"SCOOTER HOVERBOARD BATERIA"
}
],
"last":false,
"totalPages":23962,
"totalElements":23962,
"first":true,
"size":1,
"number":0,
"numberOfElements":1,
"empty":false
}
via:
JsonMapper.deserialize<PageImpl<Advertising>>(json)
I got this error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'Map<dynamic, dynamic>'
#0 JsonMapper._deserializeObject (package:dart_json_mapper/src/mapper.dart:954:9)
#1 JsonMapper._deserializeObject.<anonymous closure> (package:dart_json_mapper/src/mapper.dart:1035:13)
#2 JsonMapper._enumeratePublicProperties (package:dart_json_mapper/src/mapper.dart:593:14)
#3 JsonMapper._deserializeObject (package:dart_json_mapper/src/mapper.dart:1000:5)
#4 JsonMapper.deserialize (package:dart_json_mapper/src/mapper.dart:53:21)
The issue is related to PageImpl.content which is generic. Any tips on how to solve this?
Thanks