Open stephanegigandet opened 4 years ago
Is it possible to explicitly set the types for each and very field, instead of relying on Perl behaviour.
Is it possible to explicitly set the types for each and very field, instead of relying on Perl behaviour.
Looks like it's possible with explicit typecasting. There's also document schemas in MongoDB, but I don't know how well this would work with all the dynamic language based fields in ProductOpener.
This issue has been open 90 days with no activity. Can you give it a little love by linking it to a parent issue, adding relevant labels and projets, creating a mockup if applicable, adding code pointers from https://github.com/openfoodfacts/openfoodfacts-server/blob/main/.github/labeler.yml, giving it a priority, editing the original issue to have a more comprehensive description… Thank you very much for your contribution to 🍊 Open Food Facts
We have this long running issue (see #639) of numbers being sometimes stored as strings in MongoDB or in the JSON returned by the API. We have been fixing many examples of it, but they keep coming back.
It has to do with the way Perl handles scalars: they are automatically converted to strings or to numbers as needed, based on what is being done with them.
So for instance if we use a number as a string (e.g. to display it, to output it to a file, to log it etc.) it will internally become a string.
Unfortunately, the whole world does not use Perl, so it is causing issues for apps that parse the JSON and expect a defined type for each field.
So we need to: