Open nikitadol opened 2 years ago
I was just coming in to report this, thanks. My map's key is an enum as well, so pretty much the exact case.
Hello! Thank you for the report. JSON serialization and deserialization was kindly contributed by @knaeckeKami . Maybe he can help you. Or if you know how to fix this, I'm accepting PRs.
The code that needs to be improved is at the very end of this file: https://github.com/marcglasberg/fast_immutable_collections/blob/master/lib/src/imap/imap.dart
Meanwhile, I have published version 7.4.1, which improves the error message. It will now be an unsupported error: JSON deserialization of IMap keys of type $type are not supported at the moment.
Also, created a test for that, at the very end of this file:
Hi @marcglasberg
All keys in JSON are strings, so I don't understand why this code is here
Also, why do the _safeKeyFromJson
and _safeKeyToJson
methods exist?
Hm, I don't see a way how this could be handled without a complete overhaul of serialization.
But you can try using json_serializable_fic (https://pub.dev/packages/json_serializable_fic ). It says discontinued because I thought with the addition of the toJson, fromJson methods this package should be obsolete, but it should still work.
There is a test for enum maps (https://github.com/knaeckeKami/json_serializable_immutable_collections/blob/master/builders/json_serializable_fic/test/integration/model_test.dart ).
Error:
Minimal code: