algolia / algoliasearch-client-csharp

⚡️ A fully-featured and blazing-fast C# API client to interact with Algolia.
https://www.algolia.com/doc/api-client/getting-started/install/csharp/
MIT License
120 stars 61 forks source link

Enum serialisation issue with V7 #861

Closed morganleroi closed 1 month ago

morganleroi commented 2 months ago

There is another breaking change about JSON serialization we have seen later: the System.Text.Json serialization is set in the Algolia client to convert enums to string, while previously, they were converted to integers.

Since the Algolia client registers a global converter for doing this, it seems the only ways to adapt is either to set a custom converter on all enum properties of serialized models, or type the enum properties as int and adapt the code fetching them.

Originally posted by @fredericDelaporte in https://github.com/algolia/algoliasearch-client-csharp/issues/852#issuecomment-2322177297

morganleroi commented 2 months ago

@fredericDelaporte could you point me out what enum do you use ? In the v6 code base, there was only 3 real enum. All other properties that are now enum in v7 were string.

fredericDelaporte commented 2 months ago

In our indexes data, we have properties typed as enums. That is our own business models enums. They were converted in the indexes as ints. Now, they are converted as strings.

fredericDelaporte commented 1 month ago

Additional consequences: we build the indexes with a .Net app but search them through JavaScript. So, JavaScript code expecting integers can not work. We have put converters on all our enum and enums array properties to get them serialized as int again.

(Sure enough, string values are more descriptive than integers, but they are also more susceptible to breaking changes due to renaming, and they cause the data to be heavier. Anyway, my point is just to notify a breaking change which should be included in the upgrade guide.)

morganleroi commented 1 month ago

Hello @fredericDelaporte

Sorry for the late response. You are right, it's not an expected behaviour. We will publish a bug fix where the enum are persisted as int. We will also create a dedicated documentation about the enum behaviour + the Serialization changes.

morganleroi commented 1 month ago

@fredericDelaporte

A new minor version has been released (7.4.0). This version fixes the enum issue.

Please note that your enum will be saved at int in this version.

fredericDelaporte commented 1 month ago

Thanks.