JSON src-gen fast-path does not consider writer Encoder option #59424
Labels
area-System.Text.Json
enhancement
Product code improvement that does NOT require public API changes/additions
Priority:2
Work that is important, but not critical for the release
source-generator
Indicates an issue with a source generator feature
Milestone
When writing via the serializer e.g.
JsonSerializer.Serialize(foo, context.Foo)
, fast-path logic does not consider the encoder on the writer (viaUtf8JsonWriter.Options.Encoder
). This means property names would be written with default encoding and values could be written with a custom encoder. This mismatch can be considered invalid - we should disallow the use of a custom encoder on the writer to align with supported features for fast-path.We should also verify the behavior of both metadata and reflection-based serializers if/when
JsonSerializerOptions.Encoder
andUtf8JsonWriter.Options.Encoder
differ.Calling fast-path logic directly e.g.
context.Foo.SerializeHandler(writer, foo)
with writer encoder info that differs from options specified ahead of time via[JsonSourceGenerationOptions]
is considered a user error. The raw serialize logic will not perform any options validation.cc @eiriktsarpalis @steveharter for any thoughts.
The text was updated successfully, but these errors were encountered: