Property names should escape leading "$"s when using ReferenceHandling.Preserve #1780
Labels
area-System.Text.Json
backlog-cleanup-candidate
An inactive issue that has been marked for automated closure.
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
Today is totally acceptable that a JSON property name would be written with a leading "$" by using
JsonPropertyNameAttribute
as an example, this conflicts with metadata properties when usingReferenceHandling.Preserve
an causes the payload to be unable to round-trip.Repro:
Output:
The serialized object now contains two
"$id"
properties that will collide on deserialization and will throw aJsonException
for $id not being the first property in the JSON object.To avoid this, we must do as suggested in dotnet/apireviews#109 (comment)
There are several means of how a CLR property may end up with a "$" into its name. it can be made through IL generation or by using F# which contrary to C#, it does not constrain that properties start with an alphabetical character (IIRC).
Using only raw bytes to determine if a property is metadata or not is already performed on deserialization, so presumably no changes will be need from that side.
cc @ahsonkhan, @steveharter, @layomia
The text was updated successfully, but these errors were encountered: