Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with generic type #225

Open
digows opened this issue Jul 10, 2024 · 0 comments
Open

Error with generic type #225

digows opened this issue Jul 10, 2024 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@digows
Copy link

digows commented Jul 10, 2024

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

@digows digows changed the title Error with type generics Error with generic type Jul 10, 2024
@k-paxian k-paxian added the question Further information is requested label Jul 17, 2024
@k-paxian k-paxian self-assigned this Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants