Jaguar-dart / jaguar_serializer

Format (JSON, XML, protobuf, mongodb, etc) and platform (server, client) agnostic serialization framework
172 stars 34 forks source link

Generic classes #190

Open sutbult opened 4 years ago

sutbult commented 4 years ago

I have two classes that look like this:

class ApiError {
  final String message;
  ApiError({this.message});
}
class ApiResponse<T> {
  final T data;
  final ApiError error;
  ApiError({this.data, this.error});
}

I would like to create a serializer for ApiResponse. However, I cannot figure out how to use jaguar_serializer to achieve this. Every instance of T would have a serializer.

I have tried to specify a list containing all available serializers through the serializers argument to @GenSerializer, but this does not work as the builder does not understand how to handle T.

I have also tried to set a custom processor to the field data through the fields argument to @GenSerializer, but this does not work either as the type T cannot be found.