@@ -21,6 +21,10 @@ namespace Elastic.Clients.Elasticsearch.Serialization;
21
21
public class DefaultSourceSerializer :
22
22
SystemTextJsonSerializer
23
23
{
24
+ #if ! NET8_0_OR_GREATER
25
+ private readonly object _lock = new ( ) ;
26
+ #endif
27
+
24
28
/// <summary>
25
29
/// Constructs a new <see cref="DefaultSourceSerializer"/> instance that accepts an <see cref="Action{T}"/> that can
26
30
/// be provided to customize the default <see cref="JsonSerializerOptions"/>.
@@ -43,15 +47,23 @@ private void LinkSettings(IElasticsearchClientSettings settings)
43
47
var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
44
48
var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
45
49
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 )
47
55
{
48
- ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
49
- }
56
+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
57
+ {
58
+ ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
59
+ }
50
60
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
+ }
54
65
}
66
+ #endif
55
67
}
56
68
}
57
69
0 commit comments