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 serializer indentation #8143

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public SystemTextJsonSerializer(IElasticsearchClientSettings settings)
/// be used when serializing.
/// </summary>
/// <returns></returns>
protected abstract JsonSerializerOptions CreateJsonSerializerOptions();
protected abstract JsonSerializerOptions? CreateJsonSerializerOptions();

/// <inheritdoc />
public override T Deserialize<T>(Stream stream)
Expand All @@ -72,7 +72,7 @@ public override T Deserialize<T>(Stream stream)
}

/// <inheritdoc />
public override object Deserialize(Type type, Stream stream)
public override object? Deserialize(Type type, Stream stream)
{
Initialize();

Expand All @@ -90,7 +90,7 @@ public override ValueTask<T> DeserializeAsync<T>(Stream stream, CancellationToke
}

/// <inheritdoc />
public override ValueTask<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default)
public override ValueTask<object?> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default)
{
Initialize();
return JsonSerializer.DeserializeAsync(stream, type, Options, cancellationToken);
Expand All @@ -101,8 +101,7 @@ public override ValueTask<object> DeserializeAsync(Type type, Stream stream, Can
SerializationFormatting formatting = SerializationFormatting.None)
{
Initialize();
using var writer = new Utf8JsonWriter(writableStream);
JsonSerializer.Serialize(writer, data, typeof(T), formatting == SerializationFormatting.Indented && IndentedOptions is not null ? IndentedOptions : Options);
JsonSerializer.Serialize(writableStream, data, formatting == SerializationFormatting.Indented && IndentedOptions is not null ? IndentedOptions : Options);
}

/// <inheritdoc />
Expand All @@ -117,7 +116,7 @@ public override ValueTask<object> DeserializeAsync(Type type, Stream stream, Can
private static bool TryReturnDefault<T>(Stream stream, out T deserialize)
{
deserialize = default;
return stream == null || stream == Stream.Null || (stream.CanSeek && stream.Length == 0);
return stream is null || stream == Stream.Null || (stream.CanSeek && stream.Length == 0);
}

/// <summary>
Expand Down Expand Up @@ -152,12 +151,12 @@ protected void Initialize()

private void LinkOptionsAndSettings()
{
if (!ElasticsearchClient.SettingsTable.TryGetValue(Options, out _))
if (!ElasticsearchClient.SettingsTable.TryGetValue(Options!, out _))
{
ElasticsearchClient.SettingsTable.Add(Options, Settings);
}

if (!ElasticsearchClient.SettingsTable.TryGetValue(IndentedOptions, out _))
if (!ElasticsearchClient.SettingsTable.TryGetValue(IndentedOptions!, out _))
{
ElasticsearchClient.SettingsTable.Add(IndentedOptions, Settings);
}
Expand Down