Hi, we have a collection that has the fields written in snake case.
When registering the client, we provide a custom json serializer.
builder.Services.AddTypesenseClient(x =>
{
x.ApiKey = typesenseOptions.ApiKey;
x.Nodes =
[
new Node(
host: typesenseOptions.Url.Host,
port: typesenseOptions.Url.Port.ToString(),
protocol: typesenseOptions.Url.Scheme
)
];
x.JsonSerializerOptions ??= new JsonSerializerOptions();
x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
x.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
});
While the methods that are used for reading (such as SearchInternal) use _jsonNameCaseInsensitiveTrue, and thus respect the custom json serializer options, the ImportDocuments method uses the _jsonOptionsCamelCaseIgnoreWritingNull.
This field, when set, overrides the custom options with -- as the name implies -- the CamelCase naming policy, thus making the import fail.
Line 57
|
if (config.Value.JsonSerializerOptions is not null) |
|
{ |
|
_jsonNameCaseInsensitiveTrue = new JsonSerializerOptions(config.Value.JsonSerializerOptions) |
|
{ |
|
PropertyNameCaseInsensitive = true |
|
}; |
|
|
|
_jsonOptionsCamelCaseIgnoreWritingNull = new JsonSerializerOptions(config.Value.JsonSerializerOptions) |
|
{ |
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, |
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull |
|
}; |
|
} |
Is this behavior intended?
As of now, we've managed to circumvent this problem by serializing the documents manually, and then passing them to the import method, but if feels a bit "dirty".
Hi, we have a collection that has the fields written in snake case.
When registering the client, we provide a custom json serializer.
While the methods that are used for reading (such as
SearchInternal) use_jsonNameCaseInsensitiveTrue, and thus respect the custom json serializer options, theImportDocumentsmethod uses the_jsonOptionsCamelCaseIgnoreWritingNull.This field, when set, overrides the custom options with -- as the name implies -- the
CamelCasenaming policy, thus making the import fail.Line 57
typesense-dotnet/src/Typesense/TypesenseClient.cs
Lines 48 to 60 in f524cad
Is this behavior intended?
As of now, we've managed to circumvent this problem by serializing the documents manually, and then passing them to the import method, but if feels a bit "dirty".