Using RestSharp to retrieve JSON data, the JSON that is coming in looks like this...
{"data":{"NHL":[{"team_id":1,"team":"Colorado Avalanche","regular_season":{},"postseason":{}}]}}
The C# Objects I'm trying to serialize to looks like this.
public class NHLTeamStats
{
[DeserializeAs(Name = "data")]
public NHLTeamStatsData Data { get; set; }
}
public partial class NHLTeamStatsData
{
[DeserializeAs(Name = "NHL")]
public List<NHLTeamStatsNHL> NHL { get; set; }
}
public class NHLTeamStatsNHL
{
public NHLTeamStatsNHL()
{
RegularSeason = new NHLTeamStatsSeason();
Postseason = new NHLTeamStatsSeason();
}
[DeserializeAs(Name = "team_id")]
public int TeamId { get; set; }
[DeserializeAs(Name = "team")]
public string Team { get; set; }
[DeserializeAs(Name = "regular_season")]
public NHLTeamStatsSeason RegularSeason { get; set; }
[DeserializeAs(Name = "postseason")]
public NHLTeamStatsSeason Postseason { get; set; }
}
public class NHLTeamStatsSeason
{
[DeserializeAs(Name = "hits")]
public int? Hits { get; set; }
[DeserializeAs(Name = "goals")]
public int? Goals { get; set; }
[DeserializeAs(Name = "saves")]
public int? Saves { get; set; }
[DeserializeAs(Name = "assists")]
public int? Assists { get; set; }
[DeserializeAs(Name = "power_plays")]
public int? PowerPlays { get; set; }
[DeserializeAs(Name = "faceoffs_won")]
public int? FaceoffsWon { get; set; }
[DeserializeAs(Name = "games_played")]
public int? GamesPlayed { get; set; }
[DeserializeAs(Name = "faceoffs_lost")]
public int? FaceoffsLost { get; set; }
[DeserializeAs(Name = "shots_on_goal")]
public int? ShotsOnGoal { get; set; }
[DeserializeAs(Name = "penalty_minutes")]
public int? PenaltyMinutes { get; set; }
[DeserializeAs(Name = "power_plays_converted")]
public int? PowerPlaysConverted { get; set; }
}
When I do the RestSharp Execute call the response is empty as you can see in this screenshot. If I do the Execute method without the type specified response comes back fine. It only occurs when the properties regular_season, postseason are set to empty objects "regular_season":{},"postseason":{}
When they have data it works and serializes fine.
Any thoughts?