You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When localstore stores a document it also saves the document to memory for faster retrieval. The problem is that in doing so it makes the types returned by a cached document vs uncached documents to be different and thereby breaking json marshal/unmarshal.
The following code should demonstrate this problem:
classJsonInner {
finalString val1;
finalbool val2;
JsonInner(this.val1, this.val2);
JsonInner.fromJson(Map<String, dynamic> json):this(json['val1'],json['val2']);
Map<String, dynamic> toJson() => {
'val1': val1,
'val2': val2,
};
}
classJsonOuter {
finalJsonInner inner;
JsonOuter(this.inner);
JsonOuter.fromJson(Map<String, dynamic> json):this(JsonInner.fromJson(json['inner']));
Map<String, dynamic> toJson() => {
'inner': inner,
};
}
voidmain() async {
WidgetsFlutterBinding.ensureInitialized();
final db =Localstore.instance;
JsonOuter ob1 =JsonOuter(JsonInner("Inner", true));
String key ="uno";
String collectionName ="deus";
var data =await db.collection(collectionName).doc(key).get();
if(data ==null) {
log("Data is null. Storing");
db.collection(collectionName).doc(key).set(ob1.toJson());
log("Data stored. Now run me again!!");
return;
} else {
log("We got data: $data");
log("Unmarshalling the data to an object will work");
log("Unmarshal: ${JsonOuter.fromJson(data).toString()}");
log("Storing again and retrieving");
db.collection(collectionName).doc(key).set(ob1.toJson());
data =await db.collection(collectionName).doc(key).get();
log("Data is now: $data");
log("Unmarshalling the data to an object will fail because type of 'inner' is not the same as when you read from file");
log("Unmarshal: ${JsonOuter.fromJson(data!).toString()}");
}
}
The text was updated successfully, but these errors were encountered:
Hi.
When localstore stores a document it also saves the document to memory for faster retrieval. The problem is that in doing so it makes the types returned by a cached document vs uncached documents to be different and thereby breaking json marshal/unmarshal.
The following code should demonstrate this problem:
The text was updated successfully, but these errors were encountered: