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
Can't deserialize DateTime from Firestore, but locally it works. Both is a DateTime. #454
Comments
There's already an alternative serializer--just need to install it: Apologies for brevity, posted from phone. |
@dave26199 Thank you very much for answering, unfortunately I still get an error message.
So now instead of saying Ich changed the line: final standardSerializers =
(serializers.toBuilder()..addPlugin(new StandardJsonPlugin())).build(); to final standardSerializers =
(serializers.toBuilder()..addPlugin(new StandardJsonPlugin())..add(Iso8601DateTimeSerializer())).build(); Did I do something wrong? |
Ah, I understand now. The problem is that it actually does not need serializing at all, it's already a DateTime. You can do that following the instructions for GeoPoint here: I.e. add your own "serializer" that does nothing. Apologies for brevity, sent from phone... |
@dave26199 Thank you very much for your help! For anybody who has the same issue, here's the solution: 1. Make an own serializer, which does nothing In my case:
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
///A Serializer which does basically "nothing".
/// It is used, as a DateTime returned by Firestore is ALREADY a DateTime Object
/// and not just "data" which has to be deserialized into a DateTime.
class DateTimeSerializer implements PrimitiveSerializer<DateTime> {
final bool structured = false;
@override
final Iterable<Type> types = new BuiltList<Type>([DateTime]);
@override
final String wireName = 'GeoPoint';
@override
Object serialize(Serializers serializers, DateTime geoPoint,
{FullType specifiedType: FullType.unspecified}) {
return geoPoint;
}
@override
DateTime deserialize(Serializers serializers, Object serialized,
{FullType specifiedType: FullType.unspecified}) {
return serialized as DateTime;
}
} 2. Add the DateTimeSerializer to your serializers final serializers =
(_$serializers.toBuilder()..add(DateTimeSerializer())..addPlugin(new StandardJsonPlugin())).build(); |
I am trying to deserialize a document from Firestore into my homework object, but I get this error message:
The thing is that it works locally with DateTime.now but doesn't with the DateTime in the Firestore Document. Here is the Firestore Document returned:
homework.dart
serializers.dart
I hope it's not too much or litte...
This is my first issue ;), so if I can improve something writing these let me know.
The text was updated successfully, but these errors were encountered: