dart-archive / rpc

RPC package for building server-side RESTful Dart APIs.
https://pub.dartlang.org/packages/rpc
BSD 3-Clause "New" or "Revised" License
117 stars 49 forks source link

RPC doesn't work with Generic List<T> field into Message Class #134

Closed supermuka closed 5 years ago

supermuka commented 5 years ago

SDK 2.0.0 RPC 0.6.0

Considering the following classes:

/// User classes
class UserBase {
   String id;
}

class User implements UserBase {
   String id;
   String name;
}

/// Group classes
class GroupBase {
  String id;
}

// this class is used as a Request Message on RPC
class GroupMessage<TUser extends UserBase> implements GroupBase {
  String id;
  String name;
  String surName;
  List<TUser> members;
  GroupMessage() {
    members = List<TUser>();
  }
}

class Group implements GroupMessage<User> {
  String id;
  String name;
  String surName;
  List<User> members;

  Group() {
    members = List<User>();
  }

  String get completeName => this.name + ' ' + this.surName; 
}

The following error is thrown when an instance of GroupMessage class defined with Generics is passed as a Request Param from Client to Server-Side on RPC and the RPC try to materialize an new instance on Server-Side from Json:

Field members has wrong type: type 'List<dynamic>' is not a subtype of type 'List<UserBase>' of 'value'

NOTE 1: This error occurs with SDK 2.0.0 + Generics. In SDK 2.1.0-dev.8.0 this error occurs using normal class without Generics too, like reported on issue https://github.com/dart-lang/rpc/issues/133

NOTE 2:: This error occurs when it's used Generic into List<T> field as in the example above: List<TUser> members;

supermuka commented 5 years ago

it works fine now with PR https://github.com/dart-archive/rpc/pull/138.