Skip to content
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

Fix (de-)serialization of Fields in custom converters #8360

Merged
merged 1 commit into from
Sep 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public override void Write(Utf8JsonWriter writer, SubmitAsyncSearchRequest value
if (value.StoredFields is not null)
{
writer.WritePropertyName("stored_fields");
JsonSerializer.Serialize(writer, value.StoredFields, options);
new FieldsConverter().Write(writer, value.StoredFields, options);
}

if (value.Suggest is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public override void Write(Utf8JsonWriter writer, SearchRequest value, JsonSeria
if (value.StoredFields is not null)
{
writer.WritePropertyName("stored_fields");
JsonSerializer.Serialize(writer, value.StoredFields, options);
new FieldsConverter().Write(writer, value.StoredFields, options);
}

if (value.Suggest is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public override MultisearchBody Read(ref Utf8JsonReader reader, Type typeToConve

if (property == "stored_fields")
{
variant.StoredFields = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.Fields?>(ref reader, options);
reader.Read();
variant.StoredFields = new FieldsConverter().Read(ref reader, typeToConvert, options);
continue;
}

Expand Down Expand Up @@ -380,7 +381,7 @@ public override void Write(Utf8JsonWriter writer, MultisearchBody value, JsonSer
if (value.StoredFields is not null)
{
writer.WritePropertyName("stored_fields");
JsonSerializer.Serialize(writer, value.StoredFields, options);
new FieldsConverter().Write(writer, value.StoredFields, options);
}

if (value.Suggest is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public override SourceFilter Read(ref Utf8JsonReader reader, Type typeToConvert,
var property = reader.GetString();
if (property == "excludes" || property == "exclude")
{
variant.Excludes = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.Fields?>(ref reader, options);
reader.Read();
variant.Excludes = new FieldsConverter().Read(ref reader, typeToConvert, options);
continue;
}

if (property == "includes" || property == "include")
{
variant.Includes = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.Fields?>(ref reader, options);
reader.Read();
variant.Includes = new FieldsConverter().Read(ref reader, typeToConvert, options);
continue;
}
}
Expand All @@ -62,13 +64,13 @@ public override void Write(Utf8JsonWriter writer, SourceFilter value, JsonSerial
if (value.Excludes is not null)
{
writer.WritePropertyName("excludes");
JsonSerializer.Serialize(writer, value.Excludes, options);
new FieldsConverter().Write(writer, value.Excludes, options);
}

if (value.Includes is not null)
{
writer.WritePropertyName("includes");
JsonSerializer.Serialize(writer, value.Includes, options);
new FieldsConverter().Write(writer, value.Includes, options);
}

writer.WriteEndObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Elastic.Clients.Elasticsearch;
#endif

[JsonConverter(typeof(FieldConverter))]
[DebuggerDisplay($"{nameof(DebuggerDisplay)},nq")]
[DebuggerDisplay($"{{{nameof(DebuggerDisplay)},nq}}")]
public sealed class Field :
IEquatable<Field>,
IUrlParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Elastic.Clients.Elasticsearch.Serverless;
namespace Elastic.Clients.Elasticsearch;
#endif

[DebuggerDisplay($"{nameof(DebuggerDisplay)},nq")]
[DebuggerDisplay($"{{{nameof(DebuggerDisplay)},nq}}")]
public sealed class Fields :
IEquatable<Fields>,
IEnumerable<Field>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public override void Write(Utf8JsonWriter writer, SubmitAsyncSearchRequest value
if (value.StoredFields is not null)
{
writer.WritePropertyName("stored_fields");
JsonSerializer.Serialize(writer, value.StoredFields, options);
new FieldsConverter().Write(writer, value.StoredFields, options);
}

if (value.Suggest is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public override void Write(Utf8JsonWriter writer, SearchRequest value, JsonSeria
if (value.StoredFields is not null)
{
writer.WritePropertyName("stored_fields");
JsonSerializer.Serialize(writer, value.StoredFields, options);
new FieldsConverter().Write(writer, value.StoredFields, options);
}

if (value.Suggest is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public override MultisearchBody Read(ref Utf8JsonReader reader, Type typeToConve

if (property == "stored_fields")
{
variant.StoredFields = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Fields?>(ref reader, options);
reader.Read();
variant.StoredFields = new FieldsConverter().Read(ref reader, typeToConvert, options);
continue;
}

Expand Down Expand Up @@ -380,7 +381,7 @@ public override void Write(Utf8JsonWriter writer, MultisearchBody value, JsonSer
if (value.StoredFields is not null)
{
writer.WritePropertyName("stored_fields");
JsonSerializer.Serialize(writer, value.StoredFields, options);
new FieldsConverter().Write(writer, value.StoredFields, options);
}

if (value.Suggest is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public override SourceFilter Read(ref Utf8JsonReader reader, Type typeToConvert,
var property = reader.GetString();
if (property == "excludes" || property == "exclude")
{
variant.Excludes = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Fields?>(ref reader, options);
reader.Read();
variant.Excludes = new FieldsConverter().Read(ref reader, typeToConvert, options);
continue;
}

if (property == "includes" || property == "include")
{
variant.Includes = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Fields?>(ref reader, options);
reader.Read();
variant.Includes = new FieldsConverter().Read(ref reader, typeToConvert, options);
continue;
}
}
Expand All @@ -62,13 +64,13 @@ public override void Write(Utf8JsonWriter writer, SourceFilter value, JsonSerial
if (value.Excludes is not null)
{
writer.WritePropertyName("excludes");
JsonSerializer.Serialize(writer, value.Excludes, options);
new FieldsConverter().Write(writer, value.Excludes, options);
}

if (value.Includes is not null)
{
writer.WritePropertyName("includes");
JsonSerializer.Serialize(writer, value.Includes, options);
new FieldsConverter().Write(writer, value.Includes, options);
}

writer.WriteEndObject();
Expand Down
Loading