dart_mappable
dart_mappable copied to clipboard
Mapper for Generic class with Type bounds.
I want to create a SimpleMapper for my generic class, but the type parameter of this class is bounded. For example (modifying the GenericBox<T> example):
class NumberBox<T extends num> {
NumberBox(this.content);
final T content;
}
class NumberBoxMapper extends SimpleMapper1<NumberBox> {
const NumberBoxMapper();
@override
NumberBox<T> decode<T>(dynamic value) {
T content = MapperContainer.globals.fromValue<T>(value);
return NumberBox<T>(content);
}
@override
dynamic encode<T>(NumberBox<T> self) {
return MapperContainer.globals.toValue<T>(self.content);
}
@override
Function get typeFactory => <T>(f) => f<NumberBox<T>>();
}
is invalid as the type bounds of encode and decode are unrestricted.
Is there a way around this, I was hoping I could make NumberBoxMapper generic e.g. NumberBoxMapper<T extends num
>
Thanks 🙂