Skip to content

Commit

Permalink
Fix serializer indentation (#8143)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Apr 18, 2024
1 parent d574208 commit c51fdac
Showing 1 changed file with 7 additions and 8 deletions.
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

0 comments on commit c51fdac

Please sign in to comment.