elasticsearch-net icon indicating copy to clipboard operation
elasticsearch-net copied to clipboard

SystemTextJsonSerializer.Serialize ignores SerializationFormatting

Open VMelnalksnis opened this issue 1 year ago • 1 comments

Elastic.Clients.Elasticsearch version: 8.11.0

Elasticsearch version: -

.NET runtime version: 8.0.100

Operating system version: -

Description of the problem including expected versus actual behavior: Unlike SerializeAsync<T>, Serialize<T> creates a new Utf8JsonWriter, which has its own JsonWriterOptions, which ignore JsonSerializerOptions. If SerializationFormatting.Indented, JsonWriterOptions still defaults to Indented = false.

Steps to reproduce:

  1. Call DefaultSourceSerializer.Serialize<T> with SerializationFormatting.Indented
  2. See that JSON is in single line

Expected behavior JSON formatting follows specified SerializationFormatting.

VMelnalksnis avatar Jan 10 '24 07:01 VMelnalksnis

Thanks for reporting!

Seems like we forgot to pass custom JsonWriterOptions to the Utf8JsonWriter constructor.

flobernd avatar Jan 15 '24 08:01 flobernd