9
9
10
10
namespace Elastic . Clients . Elasticsearch . Serialization ;
11
11
12
+ /// <summary>
13
+ /// The built in internal serializer that the <see cref="ElasticsearchClient"/> uses to serialize
14
+ /// source document types.
15
+ /// </summary>
12
16
public class DefaultSourceSerializer : SystemTextJsonSerializer
13
17
{
18
+ /// <summary>
19
+ /// Returns an array of the built in <see cref="JsonConverter"/>s that are used registered with the
20
+ /// source serializer by default.
21
+ /// </summary>
14
22
public static JsonConverter [ ] DefaultBuiltInConverters => new JsonConverter [ ]
15
23
{
16
24
new JsonStringEnumConverter ( ) ,
@@ -26,20 +34,31 @@ internal DefaultSourceSerializer(IElasticsearchClientSettings settings) : base(s
26
34
Initialize ( ) ;
27
35
}
28
36
37
+ /// <summary>
38
+ /// Constructs a new <see cref="DefaultSourceSerializer"/> instance that accepts an <see cref="Action{T}"/> that can
39
+ /// be provided to customize the default <see cref="JsonSerializerOptions"/>.
40
+ /// </summary>
41
+ /// <param name="settings">An <see cref="IElasticsearchClientSettings"/> instance to which this
42
+ /// serializers <see cref="JsonSerializerOptions"/> will be linked.</param>
43
+ /// <param name="configureOptions">An <see cref="Action{T}"/> to customize the configuration of the
44
+ /// default <see cref="JsonSerializerOptions"/>.</param>
29
45
public DefaultSourceSerializer ( IElasticsearchClientSettings settings , Action < JsonSerializerOptions > configureOptions ) : base ( settings )
30
46
{
31
- if ( configureOptions is null )
32
- throw new ArgumentNullException ( nameof ( configureOptions ) ) ;
33
-
34
47
var options = CreateDefaultJsonSerializerOptions ( ) ;
35
48
36
- configureOptions ( options ) ;
49
+ configureOptions ? . Invoke ( options ) ;
37
50
38
51
_jsonSerializerOptions = options ;
39
52
40
53
Initialize ( ) ;
41
- }
54
+ }
42
55
56
+ /// <summary>
57
+ /// A factory method which returns a new instance of <see cref="JsonSerializerOptions"/> configured with the
58
+ /// default configuration applied to for serialization by the <see cref="DefaultSourceSerializer"/>.
59
+ /// </summary>
60
+ /// <param name="includeDefaultConverters"></param>
61
+ /// <returns></returns>
43
62
public static JsonSerializerOptions CreateDefaultJsonSerializerOptions ( bool includeDefaultConverters = true )
44
63
{
45
64
var options = new JsonSerializerOptions ( )
@@ -60,6 +79,13 @@ public static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool incl
60
79
return options ;
61
80
}
62
81
82
+ /// <summary>
83
+ /// A helper method which applies the default converters for the built in source serializer to an
84
+ /// existing <see cref="JsonSerializerOptions"/> instance.
85
+ /// </summary>
86
+ /// <param name="options">The <see cref="JsonSerializerOptions"/> instance to which to append the default
87
+ /// built in <see cref="JsonConverter"/>s.</param>
88
+ /// <returns>The <see cref="JsonSerializerOptions"/> instance that was provided as an argument.</returns>
63
89
public static JsonSerializerOptions AddDefaultConverters ( JsonSerializerOptions options )
64
90
{
65
91
foreach ( var converter in DefaultBuiltInConverters )
@@ -70,5 +96,5 @@ public static JsonSerializerOptions AddDefaultConverters(JsonSerializerOptions o
70
96
return options ;
71
97
}
72
98
73
- protected override JsonSerializerOptions CreateJsonSerializerOptions ( ) => _jsonSerializerOptions ;
99
+ protected sealed override JsonSerializerOptions CreateJsonSerializerOptions ( ) => _jsonSerializerOptions ;
74
100
}
0 commit comments