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

Complex data types couldn't serialize #241

Open
sc-cmendoza opened this issue Mar 2, 2021 · 7 comments
Open

Complex data types couldn't serialize #241

sc-cmendoza opened this issue Mar 2, 2021 · 7 comments

Comments

@sc-cmendoza
Copy link

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?

@wovalle
Copy link
Owner

wovalle commented Mar 8, 2021

Hey! I think tit should work.

Can you create a minimal repo reproducing the issue so I can check it out?

@skalashnyk
Copy link
Contributor

skalashnyk commented Mar 11, 2021

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))

@leandrogehlen
Copy link

This is not necessary.

Please read docs:
https://fireorm.js.org/#/README?id=usage

@wovalle
Copy link
Owner

wovalle commented Mar 12, 2021

I'll take a look at your suggestion @skalashnyk

1 similar comment
@wovalle
Copy link
Owner

wovalle commented Mar 12, 2021

I'll take a look at your suggestion @skalashnyk

@danieleisenhardt
Copy link
Contributor

If I'm not mistaken, my pull request (#251) solves this issue.

@wovalle
Copy link
Owner

wovalle commented May 11, 2021

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

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

5 participants