question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nest.JsonSerializerSettings.NullValueHandling not respected

See original GitHub issue

NEST/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:

  1. Add the below code to create an IElasticClient specifically the sourceSerializer delegate with JsonSerializerSettings.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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
russcamcommented, Aug 12, 2019

@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 👍

0reactions
russcamcommented, Jul 22, 2019

@george-weare8 any further details that you can provide for this?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found