Skip to content

Commit

Permalink
Fix (de-)serialization of Fields in custom converters (#8360)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Nov 20, 2024
1 parent 7c3a16c commit acd7765
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 18 deletions.
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

0 comments on commit acd7765

Please sign in to comment.