-1

In my project, I have multiple model classes consisting of their own JSON parsing methods, how can I use generic type to increase code reusability.

NOTE: for HTTP request am using DIO package

1 Answers1

0

The generic type you'd be referencing would have to capture the same specifics as the portion of the classes that are performing JSON parsing and serializing in your existing classes. You're just introducing a complicated interaction.

It's very hard to get past the fundamental nature of Dart, in that the member variable access cannot be somehow performed with the string names of those members. This isn't JavaScript or Perl or Ruby. :) So compile-time builder systems like json_serializable, or edit-time processing like Dart Data Class Generator for VSCode, are essential to the process.

Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70