Conversation
Custom Map Types
|
Hrm...I'm REALLY worried about the complexity added here – for a pretty narrow scenario. |
The complexity of auto-detection of when this applies, or the complexity of the implementation? I actually thought that the implementation and auto-detection were relatively straightforward. Plumbing through a flag from the annotation might be less 'magic' to the user, but would require far more changes, and would require more cognitive burden on the end user of the collection type rather than the author. As far as it being a narrow scenario. I would argue that using immutable collections in your data model is a fairly common practice, (e.g. |
|
DateTime, BigInt url for example as key works fine without hacky workaround, because these types are implemented correctly, double int, bool are not parsed correctly I think that works for the hacky woraround. With DateTime I get a cast error because the DateTime is parsed correctly with toJsonK and then _safeKeyToJson tries to parse the already converted String into DateTime again in a DatateTime. -> error. Maybe it is possible to use only hacky workaround for int double bool, until #1332 is fixed. :) |
@kevmoo
Iterated as requested on #997
Fixes: #396
See hacky workaround that is forced to do this at runtime for the fast_immutable_collections package, and is not able to handle enum keys:
https://github.com/marcglasberg/fast_immutable_collections/pull/25/files#diff-ba44d9486dfccb708bbdbbc167a5cfc096361c004eb01907d83fa4cfb2b8b889R1386
Custom map types with fromJson / toJson methods can now have keys automatically de/serialized to strings.
Usage:
Custom map types can make the fromJsonK / toJsonK parameters of their fromJson / toJson methods detected as map keys by using String? rather than Object? as the serialized type.