Nest.JsonSerializerSettings.NullValueHandling not respected
See original GitHub issueNEST/Elasticsearch.Net version: 6.8.0
Elasticsearch version: AWS Managed 6.7
Description of the problem including expected versus actual behavior:
I want my document persisted in Elastic Search to remove properties with null value. This was working before adding the Nest.JsonNetSerializer
nuget package but I had issue serializing dynamic types correctly.
Steps to reproduce:
- Add the below code to create an
IElasticClient
specifically the sourceSerializer delegate withJsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore
private static IElasticClient CreateElasticClient(
string searchUri,
IDocumentMappings documentMappings,
bool prettyJson = false,
bool alwaysThrowExceptions = true,
int maximumRetries = 3,
TimeSpan? maxRetryTimeout = null,
string awsHttpConnectionRegion = null)
{
var nodeUri = new Uri(searchUri);
var retryTimeout = maxRetryTimeout ?? TimeSpan.FromSeconds(15);
var httpConnection = awsHttpConnectionRegion.IsNullOrEmpty() ? new HttpConnection() : new AwsHttpConnection(awsHttpConnectionRegion);
var singleNodeConnectionPool = new SingleNodeConnectionPool(nodeUri);
var settings = new ConnectionSettings(
singleNodeConnectionPool,
httpConnection,
sourceSerializer: (builtin, serializationSettings) => new JsonNetSerializer(
builtin, serializationSettings,
() => new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
},
resolver => resolver.NamingStrategy = new CamelCaseNamingStrategy()))
.DefaultIndex(documentMappings.IndexStrategy)
.DefaultTypeName(documentMappings.TypeName)
.ThrowExceptions(alwaysThrowExceptions)
.DisableDirectStreaming()
.MaximumRetries(maximumRetries)
.MaxRetryTimeout(retryTimeout);
if (prettyJson)
{
settings.PrettyJson();
}
return new ElasticClient(settings);
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to set NullValueHandling.Include ...
When there is a (JSON) null value for the field, use the null_value as the field value. Defaults to not adding the field...
Read more >JsonSerializerSettings.NullValueHandling Property
Gets or sets how null values are handled during serialization and deserialization. The default value is Include. Namespace: Newtonsoft.Json
Read more >JSON serialization: Ignore selective properties or null properties
This article is to explain how to ignore null values or some properties from being serialized to JSON objects for easy transfer of...
Read more >JsonSerializerOptions.IgnoreNullValues Property
Gets or sets a value that indicates whether null values are ignored during serialization and deserialization. The default value is false.
Read more >NullValueHandling.Ignore is ignored when deserialising Json ...
Ignore setting is ignored. Since it is deserialised to an anonymous object rather a strongly typed object, if the setting is not ignored...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@george-weare8 We’re closing this issue due to inactivity; if you’re still in need of resolution, feel free to re-open with the additional details and we’d be glad to help you out 👍
@george-weare8 any further details that you can provide for this?