Fix dictionary deserialization crash on $-prefixed keys#9983
Fix dictionary deserialization crash on $-prefixed keys#9983haiyuazhang wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Add TryReadComplexType overload for IReadOnlyDictionary<string, T> that manually reads dictionary entries via Utf8JsonReader, bypassing the default System.Text.Json dictionary converter which rejects property names starting with '$' when ReferenceHandler is enabled. This fixes a crash when generating SDKs from specs with OData parameters (e.g. \) that appear as dictionary keys in example values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a \ key to the existing PutStorageTask example test data and assert it deserializes correctly. Without the fix, this reproduces the JsonException: 'Properties that start with \$ are not allowed in types that support metadata.' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
|
No changes needing a change description found. |
| return true; | ||
| } | ||
|
|
||
| public static bool TryReadComplexType<T>(this ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref IReadOnlyDictionary<string, T>? value) |
There was a problem hiding this comment.
this will also be applied for discriminatedSubtypes, since we deserialize into ireadonlydictionary. I kicked off a regen preview pipeline to make sure there isn't any unexpected regression https://dev.azure.com/azure-sdk/internal/_build/results?buildId=5994632&view=results
There was a problem hiding this comment.
@haiyuazhang it looks like the regen preview pipeline failed https://dev.azure.com/azure-sdk/internal/_build/results?buildId=5994632&view=logs&j=bb16106d-22e7-5110-6a98-db4aff7298af&t=ed160a59-989c-5a64-b845-833612591558. Can we please try running the regen preview script locally against the failing library to see if it's related to this change, or not?
Fixes #9982