json_serializable.dart
json_serializable.dart copied to clipboard
Map unrecognized keys
Is there a way to map unrecognized keys to a Map
For example I know that a json has some properties, but I want to parse also the unrecognized keys in order to implement custom logic depending on those.'
I imagine a property like Map<String, dynamic> otherFields
No such thing is provided now...an interesting feature request.
As with many of these, I worry about the added complexity.
I solved implementing the feature in the toJson/fromJson methods in my own model, but I think it would be useful to have a built-in feature
@imtoori how did you implement it?
I also think it would be useful. Now dart code has to know about every field in deserialized resource from API not to accidently null any that he is not using (when sending resource back). It would be great to just have fields that are useful in the class code and rest in the 'otherFields' map.
You can find an example here
https://github.com/GetStream/stream-chat-dart/tree/master/lib/src/models/message.dart