Object Serialization in Flutter: A Practical Approach

The article examines Flutter’s limited built-in JSON handling, explains why the popular json_serializable package can fall short for complex, generic objects, and introduces fish-serializable—a custom library with a ValueHolder, FishSerializable interface, JsonSerializer, and IntelliJ plugin—already used in production at Alibaba’s Xianyu and soon to be open-sourced.

Xianyu Technology
Xianyu Technology
Xianyu Technology
Object Serialization in Flutter: A Practical Approach

This article discusses the challenges of object serialization and deserialization in Flutter development, particularly when dealing with complex objects. While Flutter's built-in JsonCodec only supports primitive types (primitive, Map, List), the article explores why the commonly recommended json_serializable approach may not be ideal for certain use cases.

The authors present their solution: fish-serializable, a custom serialization library designed to address specific needs. The library's architecture is based on a ValueHolder class that acts as an intermediate storage for data, a FishSerializable interface that defines serialization behavior, and a JsonSerializer for JSON-specific operations.

Key challenges addressed include: Flutter's lack of reflection support (dart:mirrors is disabled), difficulties with generic type matching and nested generics, and the need for a more efficient solution than existing alternatives. The article details the design decisions, implementation strategies, and practical considerations for building a robust serialization system in Flutter.

The solution includes an IntelliJ plugin (fish-serializable-intelij-plugin) to automate code generation, making it more developer-friendly. The authors note that this approach is already being used in production at Xianyu (Alibaba's second-hand trading platform) and is planned for open-source release.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DARTFlutterMobile DevelopmentserializationJSONobject‑oriented programming
Xianyu Technology
Written by

Xianyu Technology

Official account of the Xianyu technology team

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.