fireorm
fireorm copied to clipboard
Complex data types couldn't serialize
I had read the documentation about complex data types, however I can't make it works.
I have this:
class GeoP{
latitude: number;
longitude: number;
}
@Collection()
class SomeModel{
@Type(() => GeoP)
geop: GeoP;
}
And then I do this:
const someGeoPInstance = new GeoP();
someGeoPInstance.latitude = 19.3753433;
someGeoPInstance.longitud = -99.0438667;
const someModelInstance = new SomeModel();
someModelInstance.geop = someGeoPInstance;
getRepository(SomeModel).create(someModelInstance);
And then I get this
Value for argument "data" is not a valid Firestore document. Couldn't serialize object of type "GeoP" (found in field "geop"). Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).
Is there something I'm misunderstanding?
Hey! I think tit should work.
Can you create a minimal repo reproducing the issue so I can check it out?
This error is thrown by firestore sdk
import * as admin from 'firebase-admin';
class Hello {
}
admin.firestore()
.collection('foo')
.doc('test_1')
.set({
prop: new Hello()
})
.then(console.log)
.catch(console.error);
Output:
Error: Value for argument "data" is not a valid Firestore document. Couldn't serialize object of type "Hello" (found in field "prop"). Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).
at validateUserInput ...
@wovalle , it can be fixed by serializing entity to plain object before passing to firestore SDK, e.g. JSON.parse(JSON.stringify(doc))
This is not necessary.
Please read docs: https://fireorm.js.org/#/README?id=usage
I'll take a look at your suggestion @skalashnyk
I'll take a look at your suggestion @skalashnyk
If I'm not mistaken, my pull request (https://github.com/wovalle/fireorm/pull/251) solves this issue.
Does it? My initial idea with this issue was to create a generic mapping between firestore "primitives" and fields in custom models.
Can you provide an example of how would you map a native Reference or GeoPoint with the serialization included in the PR? @danieleisenhardt