-
Notifications
You must be signed in to change notification settings - Fork 44
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
Offer a way to override the way documents are serialized in json #311
Comments
Hi @juchom, |
Actually, this is an interesting issue, in case other clients needs to do the same here are some side effects. For exemple, let say we want to serialize our documents with We will use the following objects : public class MovieWithEnum
{
public int Id { get; set; }
public string Name { get; set; }
public MovieGenre Genre { get; set; }
}
public enum MovieGenre
{
Action,
Cartoon
} Adding two movies will send this payload to Meilisearch : var task = await index.AddDocumentsAsync(new[]
{
new MovieWithEnum() { Id = 299537, Name = "Shazam!", Genre = MovieGenre.Action },
new MovieWithEnum() { Id = 166428, Name = "How to Train Your Dragon: The Hidden World", Genre = MovieGenre.Cartoon },
}); [
{
"Id":299537,
"Name":"Shazam!",
"Genre":"Action"
},
{
"Id":166428,
"Name":"How to Train Your Dragon: The Hidden World",
"Genre":"Cartoon"
}
] This is perfect, we have Now if we try to get our documents : var docs = await index.GetDocumentsAsync<MovieWithEnum>(); We will have this payload : {
"results":[
{
"Id":299537,
"Name":"Shazam!",
"Genre":"Action"
},
{
"Id":166428,
"Name":"How to Train Your Dragon: The Hidden World",
"Genre":"Cartoon"
}
],
"offset":0,
"limit":20,
"total":2
} We have Meilisearch fields : Our problem is that In order to have this working I'm going to decorate Meilisearch's objects with |
314: Make Meilisearch's objects readonly and make sure json mapping works … r=alallema a=juchom …regardless of JsonSerializerOptions # Pull Request ## What does this PR do? This PR makes sure that the server's response are well mapped to Meilisearch's objects. Make this objects read only where it makes sense. This is a first step for #311 Co-authored-by: Julien Chomarat <[email protected]> Co-authored-by: Amélie <[email protected]>
This is pretty essential actually. I'm surprised to find out it's not already supported. Especially, now that JSON serialization/deserialization source generators are becoming more and more prevalent, this is an increasingly pressing issue. |
As far as i see the only thing that needs to be adapted is to make the class public to allow overwriting? |
Description
Currently when we send a document we use the internal
JsonSerializerOptions
JsonSerializerOptionsWriteNulls
with this definitionI actually don't like the default behaviour of this settings, it converts
enum
asint
, I prefer to convert them asstring
.Some people may not like the CamelCase and want some other settings.
Basic example
We should add an api call like
SetGlobalJsonSerializerOptions
or actor
that accept one and make sure that theDefaultIgnoreCondition = JsonIgnoreCondition.Never
other it will throws.This test is very important because ignoring
null
values may lead to data losss for your customers.If I'm correct in
Constant.cs
we have twoJsonSerializerOptions
:JsonSerializerOptionsRemoveNulls
this one is not supposed to be overridden, it is used for settings and match the api requirements.JsonSerializerOptionsWriteNulls
this one is only for documents and we may want to override the way we send documents to Meilisearch with the mandatoryDefaultIgnoreCondition = JsonIgnoreCondition.Never
.What do you think of this ?
The text was updated successfully, but these errors were encountered: