Best way to deserialize a list with generic argument factory #1138
-
I'm using a generic class to wrap my API calls, which is working really well for int, bool, etc. I needed to extend it to also be able to deserialize a list like List. Currently, my setup looks like this, and it is working fine: Outer class:
Inner class:
And to get it all deserialized:
For simple types like bool, I could just write: But (kind of understandably), if I do something similar with a List, I get an error during runtime, because a List can't be cast to a List ... Is there a better way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Do: final list = json as List<Object?>;
return list.map(UserNotification.fromJson).toList(); There's little value in that |
Beta Was this translation helpful? Give feedback.
-
I do return it in most instances, but this had me puzzled ... thanks for the help! |
Beta Was this translation helpful? Give feedback.
Do:
There's little value in that
ApiResponse
class if you don't return it anyway