schultek / dart_mappable

Improved json serialization and data classes with full support for generics, inheritance, customization and more.
https://pub.dev/packages/dart_mappable
MIT License
164 stars 23 forks source link

[Feature request] MappableField to work on Mixins or interfaces #240

Open AhmedLSayed9 opened 3 weeks ago

AhmedLSayed9 commented 3 weeks ago

i.e:

mixin FooMixin {
  @MappableField(key: 'some_new_key')
  String get some;
}

@MappableClass()
class Foo with FooMixin, FooMappable {
  const Foo({
    required this.some,
  });

  @override
  final String some;
}

or

abstract class FooInterface {
  SomeInterface({
    @MappableField(key: 'some_new_key') required this.some,
  });

  final String some;
}

@MappableClass()
class Foo with FooMappable implements FooInterface {
  const Foo({
    required this.some,
  });

  @override
  final String some;
}
schultek commented 21 hours ago

Interesting concept.

Will keep this issue open, but I can't tell you when this will be done. Probably takes some time until I get to it. PRs are welcome.


Putting the annotation on the interface constructor won't work though, as the constructor is nowhere referenced on the implementing model. On a super constructor yes, but not any constructor.