Skip to content

Generic Class is not defined in Reflection.factories #3

Open

Description

@rasyadh

I have class model BaseResponses

import 'package:object_mapper/object_mapper.dart';

class BaseResponses<T> with Mappable {
  String message;
  T data;

  @override
  void mapping(Mapper map) {
    map('message', message, (v) => message = v);
    map<T>('data', data, (v) => data = v);
  }
}

and also register it in mappable factories

Mappable.factories = {
  BaseResponses: () => BaseResponses(),
};

I try to convert json to BaseResponses which T is another class model, on this case is Customer.
But when I try to call it like this:

BaseResponses<T> baseResponses = Mapper.fromJson(responseData).toObject<BaseResponses<T>>();

I got an error its throw execution error with message:

BaseResponses<Customer> is not defined in Reflection.factories

Activity

  1. markgravity commented on Feb 8, 2021

    @markgravity
    Owner

    @rasyadh please, also adding your Customer into factories and mixin it with Mappable

  2. rasyadh commented on Feb 8, 2021

    @rasyadh
    Author

    @markgravity already adding it, but still got the same error

  3. markgravity commented on Feb 13, 2021

    @markgravity
    Owner

    @rasyadh oh, I found the problem. When we define like this

    Mappable.factories = {
      BaseResponses: () => BaseResponses(),
    };

    it means

    Mappable.factories = {
      BaseResponses: () => BaseResponses<dynamic>(),
    };

    so that it will throw the error.
    I will look further for a better solution for your case

  4. rasyadh commented on Feb 18, 2021

    @rasyadh
    Author

    @markgravity thank you, I think it will be great if we can do so
    I will try to do work around on this as well

  5. MrPlancton commented on Feb 22, 2023

    @MrPlancton

    Any solution? :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions