JsonPropertyAttribute not working with . in name

Viewed 1978

I'm creating an Azure DevOps webhook endpoint for a work item creation trigger using ASP.NET Core 3.1. The payload produced by DevOps has . characters in some property names on the Fields array

"System.AreaPath": "FabrikamCloud",
"System.TeamProject": "FabrikamCloud",
"System.IterationPath": "FabrikamCloud\\Release 1\\Sprint 1",
"System.WorkItemType": "Bug",
"System.State": "New",
"System.Reason": "New defect reported",
"System.CreatedDate": "2014-07-15T17:42:44.663Z",
"System.CreatedBy": {

I've created models to represent the various levels of the object graph and the parents are serialising nicely but even if I annotate these properties appropriately they don't de-serialise and all values are set to defaults

public class Fields
{
    [JsonProperty("System.AreaPath")]
    public string SystemAreaPath { get; set; }

    [JsonProperty("System.TeamProject")]
    public string SystemTeamProject { get; set; }

    [JsonProperty("System.IterationPath")]
    public string SystemIterationPath { get; set; }

    [JsonProperty("System.WorkItemType")]
    public string SystemWorkItemType { get; set; }

    [JsonProperty("System.State")]
    public string SystemState { get; set; }

    [JsonProperty("System.Reason")]
    public string SystemReason { get; set; }

    [JsonProperty("System.CreatedDate")]
    public DateTime SystemCreatedDate { get; set; }

    [JsonProperty("System.CreatedBy")]
    public UserDetails SystemCreatedBy { get; set; }

    [JsonProperty("System.ChangedDate")]
    public DateTime SystemChangedDate { get; set; }

    [JsonProperty("System.ChangedBy")]
    public UserDetails SystemChangedBy { get; set; }

    [JsonProperty("System.Title")]
    public string SystemTitle { get; set; }

Anyone know how to deal with property names containing the decimal point?

2 Answers

You can use

[JsonPropertyName("System.AreaPath")]

instead of

[JsonProperty("System.AreaPath")] 

from System.Text.Json, which is used by default in .net core 3 as mentioned by @Hintee

Related