Skip to content

Implement Write method on SourceConfigConverter #7182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Elastic.Clients.Elasticsearch/Types/SourceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,15 @@ internal class SourceConfigConverter : JsonConverter<SourceConfig>
return null;
}

public override void Write(Utf8JsonWriter writer, SourceConfig value, JsonSerializerOptions options) => throw new NotImplementedException();
public override void Write(Utf8JsonWriter writer, SourceConfig value, JsonSerializerOptions options)
{
if (value.HasBoolValue)
{
writer.WriteBooleanValue(value.Item1);
}
else
{
JsonSerializer.Serialize(writer, value.Item2, options);
}
}
}
34 changes: 34 additions & 0 deletions tests/Tests/Search/Search/SearchRequestSerialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch.Core.Search;
using Tests.Serialization;
using VerifyXunit;

namespace Tests.Search.Search;

[UsesVerify]
public class SearchRequestSerialization : SerializerTestBase
{
[U]
public async Task SearchRequestWithSourceProperty_SerializesCorrectly()
{
var descriptor = new SearchRequestDescriptor("test")
.Source(new SourceConfig(false));

var json = await SerializeAndGetJsonStringAsync(descriptor);

await Verifier.VerifyJson(json);

var searchRequest = new SearchRequest("test")
{
Source = new SourceConfig(false),
};

var objectJson = await SerializeAndGetJsonStringAsync(searchRequest);
objectJson.Should().Be(json);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
_source: false
}