0

I generate a C# client from a .NET 4.8 Web API with NSwagStudio and everything works fine (all get requests) except for the posts. This is due to a wrong JSON serializer setting when converting an object to string.

If I construct the body like this

var content = new StringContent(JsonConvert.SerializeObject(par), Encoding.UTF8, "application/json");

things work, but NSwagStudio uses something like this code:

var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(myParams, _settings.Value);
var dictionary_ = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, string>>(json_, _settings.Value);
var content_ = new System.Net.Http.FormUrlEncodedContent(dictionary_);

which result in the body being null when received by the Web API. It seems the UTF8 setting is missing somewhere.

I guess I can fix this with some sort of JsonSerializerSetting, but I don't know where?

joachim_b
  • 173
  • 11

1 Answers1

0

Check in the json have in consumes and produces only one type:

"consumes": [
             "application/json" 
             ],
"produces": [
             "application/json"
             ],

link #3414 NSwagstudio https://github.com/RicoSuter/NSwag/issues/3414

Trovex
  • 1