Skip to content

DefaultFieldNameInferrer (ToCamelCase) doesn't work like CamelCase of serializers #8273

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

Closed
cwuethrich opened this issue Jul 28, 2024 · 3 comments · Fixed by #8278
Closed
Labels
8.x Relates to a 8.x client version Area: Client Category: Enhancement

Comments

@cwuethrich
Copy link

Elastic.Clients.Elasticsearch version: 8.14.6

Elasticsearch version: 8.14.3

.NET runtime version: all

Operating system version: all

Description of the problem including expected versus actual behavior:
The ToCamelCase extension as backup of the DefaultFieldNameInferrer doesn't work like the CamelCase namigs of System.Text.Json or Newtonsoft.Json. For example a property named DBName ends as dBName instead of dbName.
This behavior ends in exceptions if you use strict mapping.

Steps to reproduce:

var settings = ***
var client = new ElasticsearchClient(settings);

string indexName = "test";
var createIndexResponse = await client.Indices.CreateAsync<MyDocument>(indexName, d => d
	.Mappings(m => m
		.Dynamic(DynamicMapping.Strict)
		.Properties(p => p
			.Keyword(d => d.DBName)
		)
	));
if (!createIndexResponse.IsSuccess())
{
	if (createIndexResponse.TryGetOriginalException(out Exception ex))
		throw ex;
}

var indexResponse = await client.IndexAsync(
	document: new MyDocument() { DBName = "database" },
	index: indexName,
	id: null);
if (!indexResponse.IsSuccess())
{
	if (indexResponse.TryGetOriginalException(out Exception ex))
		throw ex; // throws strict_dynamic_mapping_exception 
}

Expected behavior
The property name DBName should ends as dbName in property mapping.

@cwuethrich cwuethrich added 8.x Relates to a 8.x client version Category: Bug labels Jul 28, 2024
@flobernd
Copy link
Member

Hi @cwuethrich, thanks for reporting! I'll have a look.

The current implementation of ToCamelCase is a very simple stub, if I remember correctly.

@cwuethrich
Copy link
Author

Hi @flobernd
This got merged impressively fast. Thanks a lot!

@flobernd
Copy link
Member

No problem at all @cwuethrich ! Thanks again for the PR. A new release with the fix included will happen later this week 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to a 8.x client version Area: Client Category: Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants