-
Notifications
You must be signed in to change notification settings - Fork 15
Description
In dart:convert, in the json to string encoder, the dart objects are passed to the toEncodable function or are treated as dynamic and the toJson method is called https://github.com/dart-lang/sdk/blob/d86f0e2836d0941776f911dfc86ff444121fd29d/sdk/lib/convert/json.dart#L521 , and if an NoSuchMethod is thrown, the encoder catches the error and throws an encoding error.
This library could do something similar. If the object is not an Map<String, dynamic>, then the toJson function gets called and in case it throws a NoSuchMethod, you can add no info, otherwise add the resulting json. This allows using standard codegen libraries, instead of having to wire everything up or making an MappableFromJson mixin which uses the toJson method (what im gonna use rn).