Closed
Description
Steps To Reproduce
Consider the following code:
static async Task Main(string[] args)
{
var http = new HttpClient();
http.BaseAddress = new System.Uri("http://localhost:5000");
var api = RestService.For<IDictionaryTestApi>(http, new RefitSettings
{
// uncomment this line and it works:
// ContentSerializer = new NewtonsoftJsonContentSerializer()
});
var body = new Dictionary<string, Dictionary<string, object>>
{
{ "outerKey", new Dictionary<string, object>
{
{ "innerKey", "innerString" },
{ "innerKey2", new object() },
{ "innerKey3", new { someProperty = "some value", otherProperty = 42 } }
}
}
};
// serializes fine
var bodyJson = System.Text.Json.JsonSerializer.Serialize(body);
// deserializes fine
var bodyPoco = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, object>>>(bodyJson);
// the api definition is as follows:
// [Post("/DictionaryTest/objectsDictionary")]
// Task<Dictionary<string, Dictionary<string, object>>> ObjectsDictionary([Body] Dictionary<string, Dictionary<string, object>> body);
var response = await api.ObjectsDictionary(body); // crashes here
Print(response); // Omitted
}
It works when I switch to Newtonsoft.Json (also version 6.0.21). The test api used in the example simply echoes what's thrown at it.
Expected behavior
It should not throw an exception.
Environment
- OS: Windows 10 Pro x64 Version 2004
- Device: not relevant
- Version: Refit 6.0.21 on .NET SDK 5.0.103
- Working Version: Refit 5.2.4