I’m using System.Text.Json.Serialization
and I have a class for query. In this class, I customize the JsonPropertyName
attribute to "site"
.
public class SearchQuery
{
[JsonPropertyName("site")]
public string SiteName { get; set; }
}
My expected behavior is that when I hit the URL:
https://example.com/search?site=sandbox
the query.SiteName
is "sandbox"
. However, [JsonPropertyName("site")]
is ignored. The current behavior is that only when I hit the URL:
https://example.com/search?siteName=sandbox
the query.SiteName
is "sandbox"
.
Is there any way to customize property names in query parameters using System.Text.Json.Serialization
?
Ank is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.