Discussion on the Json Serialization and Deserialization

10 views
Skip to first unread message

Jim Xu

unread,
Dec 19, 2019, 9:57:10 PM12/19/19
to Dart Compiler Developers
Hi, all
As you know, since Dart doesn't recommend mirror, we can handle Json serialization&deserialization with SourceGen. However, from my point of view, SourceGen has following weak points:

1. Doesn't support generic type. for example, you defined a Json class like
class UserDataT <T, T1, T2, T3,T4>{
T name;
@JsonField(true,'city1')
T city;
T1 age;
List<T3> children;
T4 birthday;
Map<String, T2> houses;
}
 2. Doesn't support customized serialization strategy, like serialization all fields of Json object to string, convert Json object to array, etc. And vice versa for deserialization.
     To be more detail, I want serialize the above class to Json composed with all string. That is to say, the age, birthday all will be of string type, instead of the original type like int and datetime.
3. The SourceGen is not so fit with our traditional experience, we may like some way to do as following: 
 final UserDataT<String, int, String, Child, DateTime> userDataT = JsonParser.fromJson<UserDataT<String, int, String, Child, DateTime>>(jsonDecode(str));
 
For the above issue, I have implemented a JsonParser based on Kernel transformer. Under the hood, I will transform the dill to generate the customized serialization&deserialization logics.

I am planning to open source this framework, but I am afraid it will be affect by the experience of Kernel transform of Dart. Therefore, with this issue, I urge Dart team to support customization of kernel transform pipeline. I am sure a lot of useful framework will be rising base on this feature.
By the way, I have came up with an issue for Dart in the github. Please give me support if you feel the same way. The link is here: https://github.com/dart-lang/sdk/issues/39879

Thanks,
Jim

Reply all
Reply to author
Forward
0 new messages