Serialized pit trod on Flutter

When interfaces interact, especially when we want to return data that has a fixed wrapper, we do that in.NET

    public class ResponseInfo<T>
    {
        public T Data { get; set; }

        public bool IsSuccess { get; set; }

        public string Msg { get; set; }

        public ResponseInfo(bool isSuccess, string msg = "Success") { IsSuccess = isSuccess; Msg = msg; }}Copy the code

In this way, the deserialization can also call Data directly to access specific Data. The Dart language is good, but it’s not as concise as C# (I probably didn’t know such a library existed, but please comment). The official tutorial recommends using jSON_serializable to serialize and deserialize an object with automatic code generation, which is already very convenient. But I still want the simplicity and convenience of C# to solve this generic serialization problem.

“How to Gracefully serialize an object on Fluter” only made me realize Dart had a pain point in serialization. The post was too high-level to understand what the solution was, but the built_value was mentioned in the comments at the end, which seemed to see the promise, so I buried my head in research. It turns out that there really is no generic deserialization like C#, and built_value is more complex to use than json_serializable, and may exist for more than just serialization. In fact, json_serializable already fully supports interface interaction, but it takes one step more than C# to separate Data and convert it to the type we want. In this project, there are two ways to use serialization, and you can compare them, and you can discuss what you have.