@@ -21,6 +21,10 @@ namespace Elastic.Clients.Elasticsearch.Serialization;
2121public class DefaultSourceSerializer :
2222 SystemTextJsonSerializer
2323{
24+ #if ! NET8_0_OR_GREATER
25+ private readonly object _lock = new ( ) ;
26+ #endif
27+
2428 /// <summary>
2529 /// Constructs a new <see cref="DefaultSourceSerializer"/> instance that accepts an <see cref="Action{T}"/> that can
2630 /// be provided to customize the default <see cref="JsonSerializerOptions"/>.
@@ -43,16 +47,24 @@ private void LinkSettings(IElasticsearchClientSettings settings)
4347 var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
4448 var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
4549
46- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
50+ #if NET8_0_OR_GREATER
51+ ElasticsearchClient . SettingsTable . TryAdd ( options , settings ) ;
52+ ElasticsearchClient . SettingsTable . TryAdd ( indentedOptions , settings ) ;
53+ #else
54+ lock ( _lock )
4755 {
48- ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
49- }
56+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
57+ {
58+ ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
59+ }
5060
51- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
52- {
53- ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
61+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
62+ {
63+ ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
64+ }
5465 }
5566 }
67+ #endif
5668}
5769
5870/// <summary>
0 commit comments