I can’t seem to solve this one. All other questions i can find with the same issue are for Newtonsoft.Json.
I use an external provided json API which returns a dictionary. But if it’s empty, they return an empty array:
With data:
"booking/index": {
"key": {
data...
}
}
Without data:
"booking/index": []
So the System.json deserializer fails with this error (which is understandable):
System.Text.Json.JsonException: The JSON value could not be converted to System.Collections.Generic.Dictionary`2[System.String,checkfront_reports.Models.Api.BookingIndexIndexObj]. Path: $[‘booking/index’] | LineNumber: 0 | BytePositionInLine: 408.
For reference here is the call i make and the data model:
var bookingIndex = await httpClient.GetFromJsonAsync<BookingIndexObj>($"booking/index?start_date={startDate.ToString("yyyy-MM-dd")}&end_date={endDate.ToString("yyyy-MM-dd")}");
public class BookingIndexObj
{
public BookingRequestObj Request { get; set; }
[JsonPropertyName("booking/index")]
public Dictionary<string, BookingIndexIndexObj> BookingIndex { get; set; }
}
public class BookingIndexIndexObj
{
public string? Code { get; set; }
[JsonPropertyName("status_id")]
public string? StatusId { get; set; }
}
public class BookingRequestObj
{
public int Page { get; set; }
public int Pages { get; set; }
}