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

Strings deserialized as BigInts #98

Open
insulationman opened this issue Oct 18, 2024 · 2 comments
Open

Strings deserialized as BigInts #98

insulationman opened this issue Oct 18, 2024 · 2 comments

Comments

@insulationman
Copy link

Strings are interpreted as BigInts if they contain only numbers. This happens when i get data from a collection of projections using findOne.

An error is then thrown when i send these objects in an api response, since BigInts are not properly serialized.

@oskardudycz
Copy link
Contributor

@insulationman, indeed, that's an unexpected side effect of the recent changes when I introduced the custom serialiser to support the _version property.

I'm going to need to make it smarter, let me outline the challenges:

  • BigInt support in JSON.parse and stringify is non-existing out of the box, that's why I introduced JSONSerialiser (available in @event-driven-io/dumbo) that's capable of serialising it,
  • when serialising, that's pretty easy as I know the type. When deserialising back it's hard, as the string could be either bigint or just a string (as you mentioned).

There are multiple strategies how to deal with that:

  • custom encoding, but that makes filtering more complex and also passing the serialised string as it is,
  • adding the custom metadata about the type or using document schema.

I'll probably go with the second option, as it'll be useful also for other cases. But this will take a bit time.

So, as a quick fix, you could use the JSONSerialiser to serialise the payload; if that's urgent, I could also try to provide the fix that changes the default serialisation behaviour, not to (de)serialise version as a string.

@insulationman thoughts?

Also, as I have you here, could you share a bit more about your setup? I'd be happy to get more information on another possible alignment to use Pongo for you. Thank you in advance!

@insulationman
Copy link
Author

Sounds good! For now i will just validate for number only strings, as the application is simple.

I'm building an mvp for niche service that relates to file uploads and processing. I like the event sourcing methodology so i started using Emmet with Pongo. Fits like a glove.

This is my first serious express/ts backend so I'm learning a lot.

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

2 participants