Skip to content

System.Text.Json custom converter for Dictionary<string, object> collides with JsonExtensionData #60560

Open
@florianbader

Description

@florianbader

Description

Implementing a custom converter for a Dictionary<string, object> is used to serialize JsonExtensionData properties but there is no way for the converter to know if it is serializing an extension property or a dictionary property. Because of that invalid JSON is generated.

Reproduction Steps

See fiddle: https://dotnetfiddle.net/VIrtyu

Expected behavior

The custom converter should have a way to check if the current write operation value is json extension data.
{"RegularData":{"World":"Hello"},"Hello":"World"}

Actual behavior

The custom converter does not know if it json extension data and therefore writes an object instead of weaving the properties into the parent.
{"RegularData":{"World":"Hello"},{"Hello":"World"}}

Regression?

No response

Known Workarounds

No response

Configuration

.NET 5, System.Text.Json 5.0.2

Other information

Might be related to #32903

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.Jsonbreaking-changeIssue or PR that represents a breaking API or functional change over a prerelease.bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions