Skip to content

Commit 273e94f

Browse files
Generate sorting types (#6511) (#6512)
* Removal of manual handling for sorts * Additional sort types * Renamed container factory method args * Improve container + additional property serialisation * Simplify properties which are single or many * Updated serialisation with tests passing * Fix BOM and update test Co-authored-by: Steve Gordon <[email protected]>
1 parent 3c3ca9a commit 273e94f

File tree

233 files changed

+4566
-4424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+4566
-4424
lines changed

src/Elastic.Clients.Elasticsearch.JsonNetSerializer/ConnectionSettingsAwareSerializerBase.Customization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Elastic.Clients.JsonNetSerializer
1515
{
16-
public abstract partial class ConnectionSettingsAwareSerializer : SourceSerializer
16+
public abstract partial class ConnectionSettingsAwareSerializer : Serializer
1717
{
1818
// Default buffer size of StreamWriter, which is private :(
1919
internal const int DefaultBufferSize = 1024;

src/Elastic.Clients.Elasticsearch/Common/Configuration/ElasticsearchClientSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ElasticsearchClientSettings : ElasticsearchClientSettingsBase<Elast
2222
/// documents.
2323
/// By default, the internal serializer will be used to serializer all types.
2424
/// </summary>
25-
public delegate SourceSerializer SourceSerializerFactory(Serializer builtIn,
25+
public delegate Serializer SourceSerializerFactory(Serializer builtIn,
2626
IElasticsearchClientSettings values);
2727

2828
/// <summary> The default user agent for Elastic.Clients.Elasticsearch </summary>

src/Elastic.Clients.Elasticsearch/Common/Infer/Field/FieldConverter.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,48 @@ internal sealed class FieldConverter : JsonConverter<Field>
2828

2929
case JsonTokenType.String:
3030
return new Field(reader.GetString());
31+
32+
case JsonTokenType.StartObject:
33+
return ReadObjectField(ref reader);
3134
}
3235

33-
reader.Read();
3436
return null;
3537
}
3638

39+
private static Field ReadObjectField(ref Utf8JsonReader reader)
40+
{
41+
var field = string.Empty;
42+
var format = string.Empty;
43+
44+
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
45+
{
46+
if (reader.TokenType == JsonTokenType.PropertyName)
47+
{
48+
var propertyName = reader.GetString();
49+
reader.Read();
50+
51+
switch (propertyName)
52+
{
53+
case "field":
54+
field = reader.GetString();
55+
break;
56+
case "format":
57+
format = reader.GetString();
58+
break;
59+
default:
60+
throw new JsonException("Unexpected property while reading `Field`.");
61+
}
62+
}
63+
}
64+
65+
if (!string.IsNullOrEmpty(field) && !string.IsNullOrEmpty(format))
66+
{
67+
return new Field(field, format);
68+
}
69+
70+
throw new JsonException("Unable to read `Field` from JSON.");
71+
}
72+
3773
public override void Write(Utf8JsonWriter writer, Field value, JsonSerializerOptions options)
3874
{
3975
if (value is null)

src/Elastic.Clients.Elasticsearch/FutureGenerated/FieldType.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/Elastic.Clients.Elasticsearch/Serialization/DefaultRequestResponseSerializer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal class CustomizedNamingPolicy : JsonNamingPolicy
2525
/// <summary>
2626
/// The built in internal serializer that the high level client Elastic.Clients.Elasticsearch uses.
2727
/// </summary>
28-
internal class DefaultRequestResponseSerializer : SystemTextJsonSourceSerializer
28+
internal class DefaultRequestResponseSerializer : SystemTextJsonSerializer
2929
{
3030
private readonly IElasticsearchClientSettings _settings;
3131

@@ -46,7 +46,6 @@ public DefaultRequestResponseSerializer(IElasticsearchClientSettings settings)
4646
new IdConverter(settings),
4747
new FieldConverter(settings),
4848
new FieldValuesConverter(settings),
49-
new SortCollectionConverter(settings),
5049
new LazyDocumentConverter(settings),
5150
new RelationNameConverter(settings),
5251
new JoinFieldConverter(settings),
@@ -60,7 +59,7 @@ public DefaultRequestResponseSerializer(IElasticsearchClientSettings settings)
6059
new IsADictionaryConverter(),
6160
new ResponseItemConverterFactory(),
6261
new UnionConverter(),
63-
new SingleOrManyConverterFactory(),
62+
new ExtraSerializationData(settings)
6463
},
6564
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
6665
};

src/Elastic.Clients.Elasticsearch/Serialization/DefaultSourceSerializer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
namespace Elastic.Clients.Elasticsearch;
99

10-
internal class DefaultSourceSerializer : SystemTextJsonSourceSerializer
10+
internal class DefaultSourceSerializer : SystemTextJsonSerializer
1111
{
12-
public DefaultSourceSerializer(IElasticsearchClientSettings settings, JsonSerializerOptions? options = null) => Options =
13-
options ?? new JsonSerializerOptions
12+
public DefaultSourceSerializer(IElasticsearchClientSettings settings, JsonSerializerOptions? options = null) =>
13+
Options = options ?? new JsonSerializerOptions
1414
{
1515
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
1616
Converters =
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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;
6+
using System.Text.Json;
7+
using System.Text.Json.Serialization;
8+
9+
namespace Elastic.Clients.Elasticsearch;
10+
11+
/// <summary>
12+
/// This actually does not ever get used as a converter. It's just an ugly hack to provide a way to
13+
/// access out settings in generated converters without requiring a mechanism to conditionally add them.
14+
/// </summary>
15+
internal sealed class ExtraSerializationData : JsonConverter<ExtraSerializationData>
16+
{
17+
public ExtraSerializationData(IElasticsearchClientSettings settings) => Settings = settings;
18+
19+
public IElasticsearchClientSettings Settings { get; }
20+
21+
public override ExtraSerializationData? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotImplementedException();
22+
public override void Write(Utf8JsonWriter writer, ExtraSerializationData value, JsonSerializerOptions options) => throw new NotImplementedException();
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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;
6+
using System.Collections.Generic;
7+
using System.Text.Json;
8+
using System.Text.Json.Serialization;
9+
10+
namespace Elastic.Clients.Elasticsearch
11+
{
12+
internal abstract class IEnumerableSingleOrManyConverter<TItem> : JsonConverter<IEnumerable<TItem>>
13+
{
14+
public override IEnumerable<TItem>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
15+
SingleOrManySerializationHelper.Deserialize<TItem>(ref reader, options);
16+
17+
public override void Write(Utf8JsonWriter writer, IEnumerable<TItem> value, JsonSerializerOptions options) =>
18+
SingleOrManySerializationHelper.Serialize<TItem>(value, writer, options);
19+
}
20+
}

src/Elastic.Clients.Elasticsearch/Serialization/SingleOrManyAttribute.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Elastic.Clients.Elasticsearch/Serialization/SingleOrManyConverterFactory.cs

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)