-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow non-String map keys, if there exists a compatible converter #396
Comments
Or |
I'd really like to be able to use value objects in place of @JsonSerializable()
class ContainerThing {
Map<ThingId, int> stuff;
}
class ThingId extends StringValue {
ThingId(String value) : super(value);
}
class StringValue extends Value<String> {
StringValue(String value) : super(value);
}
class StringValueConverter implements JsonConverter<StringValue, String> {
@override
StringValue fromJson(String json) => StringValue(json);
@override
String toJson(StringValue object) => object.value;
}
@immutable
abstract class Value<T> {
final T value;
Value(this.value);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Value &&
runtimeType == other.runtimeType &&
value == other.value;
@override
int get hashCode => value.hashCode;
}
|
@bgetsug – right now, no. I've wired through support for known types. Getting this generic for an arbitrary key type will be...interesting. 😄 I think I can pull it off, though. |
Any update on this feature? |
Nope. Prs welcome! |
The basics seems to work for regular maps (Map<int, int>), but not for maps that implement their own toJsonK / toJsonV / fromJsonK / fromJsonV converters such as IMap<int, int> from the fast_immutable_collections package. For that sort of use case, a |
Map<Version, int>
should be doable...The text was updated successfully, but these errors were encountered: