Skip to content

Commit 896028f

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Implement Write method on SourceConfigConverter (#7182)
1 parent 8cb751c commit 896028f

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/Elastic.Clients.Elasticsearch/Types/SourceConfig.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,15 @@ internal class SourceConfigConverter : JsonConverter<SourceConfig>
6060
return null;
6161
}
6262

63-
public override void Write(Utf8JsonWriter writer, SourceConfig value, JsonSerializerOptions options) => throw new NotImplementedException();
63+
public override void Write(Utf8JsonWriter writer, SourceConfig value, JsonSerializerOptions options)
64+
{
65+
if (value.HasBoolValue)
66+
{
67+
writer.WriteBooleanValue(value.Item1);
68+
}
69+
else
70+
{
71+
JsonSerializer.Serialize(writer, value.Item2, options);
72+
}
73+
}
6474
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Elastic.Clients.Elasticsearch.Core.Search;
8+
using Tests.Serialization;
9+
using VerifyXunit;
10+
11+
namespace Tests.Search.Search;
12+
13+
[UsesVerify]
14+
public class SearchRequestSerialization : SerializerTestBase
15+
{
16+
[U]
17+
public async Task SearchRequestWithSourceProperty_SerializesCorrectly()
18+
{
19+
var descriptor = new SearchRequestDescriptor("test")
20+
.Source(new SourceConfig(false));
21+
22+
var json = await SerializeAndGetJsonStringAsync(descriptor);
23+
24+
await Verifier.VerifyJson(json);
25+
26+
var searchRequest = new SearchRequest("test")
27+
{
28+
Source = new SourceConfig(false),
29+
};
30+
31+
var objectJson = await SerializeAndGetJsonStringAsync(searchRequest);
32+
objectJson.Should().Be(json);
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
_source: false
3+
}

0 commit comments

Comments
 (0)