-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use Properties with $-character when reading System.Text.Json metadata. #79482
Comments
Seems to be related to System.Text.Json: Turning off polymorphism is not an option, since I cannot solve my issue then... and in case of escaping I am not sure what is meant, but most likely I don't have the dollar then anymore. |
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsIs there an existing issue for this?
Describe the bugMy json documents contain fields with leading $-character. In general this is no issue, I can add a [JsonProperty("$something")] to the property and it's serialized correctly. In some cases I need polymorphism. In this case the minimal API is breaking. Sample:
I am using the following minimal API:
Deserializing the following works fine: But this does not: Whenever a property with a leading dollar sign is passed within the polymorophic class, it breaks. On the non polymorphic it is no problem (see Root) This seems to be related to the fact that dollars are interpreted as metadata and polymorphism is using metadata for the discriminator... I found some Any suggestions how I could still deserialize the document I get passed with dollars in this case? Expected BehaviorDeserializing should allow dollar signs on polymorphic classes just like on non polymorphic ones. Steps To ReproduceNo response Exceptions (if any)The minimal API returns error code 500 with the following message:
.NET Version7 Anything else?No response
|
Might be a more general case of #79059 |
Yes, this is a by-design restriction of the STJ metadata reader. Further investigation is needed to determine the original motivations and whether they are still valid, but we should definitely look at relaxing this in the future. |
Is there an existing issue for this?
Describe the bug
My json documents contain fields with leading $-character. In general this is no issue, I can add a [JsonProperty("$something")] to the property and it's serialized correctly.
In some cases I need polymorphism. In this case the minimal API is breaking.$), here any further property using a leading $ -character cannot be used.
While the new JsonPolymorphic feature works as expected by defining some discriminator (which can have a leading
Sample:
I am using the following minimal API:
Deserializing the following works fine:
{ "$more": { "$type": "b", "cents": "foo" }
But this does not:
{ "$more": { "$type": "a", "$dollar": "foo" }
Here the delegate is not even called, but the endpoint returns error 500.
Whenever a property with a leading dollar sign is passed within the polymorophic class, it breaks. On the non polymorphic it is no problem (see Root)
This seems to be related to the fact that dollars are interpreted as metadata and polymorphism is using metadata for the discriminator... I found some
JsonSerializerSettings
that would allow to mess arround withMetadataPropertyHandling
, but seems that's nothing I can set for Minimal API in .NET 7.Any suggestions how I could still deserialize the document I get passed with dollars in this case?
Expected Behavior
Deserializing should allow dollar signs on polymorphic classes just like on non polymorphic ones.
Steps To Reproduce
No response
Exceptions (if any)
The minimal API returns error code 500 with the following message:
Internal error. System error or malformed request. (Failed to read parameter "Root content" from the request body as JSON.)
.NET Version
7
Anything else?
No response
The text was updated successfully, but these errors were encountered: