Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contextual custom types/encoding (for DateTime & Firestore Timestamps) #1449

Open
jimmyff opened this issue Oct 11, 2024 · 0 comments
Open

Comments

@jimmyff
Copy link

jimmyff commented Oct 11, 2024

Hi, I have a large app using built_value and I'm migrating it to using freezed and json_serializable. The app has data models that are shared between the client and server. When they are serialized to/from Firestore the DateTime objects are converted to Timestamps. With built_value I have two sets of serializers, one results in pure Dart DateTime objects and the other (firestoreSerializers) handles the pesky Timestamps, as these are passed to and from the json methods I have the flexibility to use the necessary serializers based on the context:

// Current solution of passing serializers (not using json_serializable)
FooBar.fromJsonMap(
      Serializers serializers, Map<String, dynamic> data) => 
         serializers.deserializeWith(ChatMessage.serializer, data)!;

 Map<String, dynamic> toJsonMap(Serializers serializers) =>
         Map.of(serializers.serialize(this, //....

Is there a Json Serializable recommended way to give me the flexibility to share the same data models but handle the serialization & deserialization of DateTime's differently according to context requirements? There are situations where both the client and server need to serialize & deserialize objects to/from firestore as well as none-Firestore contexts (sending/receiving the objects with cloud-endpoint, caching etc).

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant