Unexpected character encountered while parsing value: [. Path 'Listing', line 3, position 14....
JanGasperan opened this issue · 0 comments
Hello,
I am encountering an error when trying to call the generated Client method. My method takes a RequestDto that has an array property. I get the Exception
public partial class RequestDto
{
public int Emailadress { get; set; }
public string[]? Listing { get; set; }
}
nswag generates the Client with
public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICollection<ResponseDto>> SearchAsync(RequestDto req, System.Threading.CancellationToken cancellationToken)
{
if (req == null)
throw new System.ArgumentNullException("req");
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(req, _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_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, string>> - throw the exception -> Unexpected character encountered while parsing value: [. Path 'Listing', line 3, position 14....
Is there a configuration I need to set or change to be able to use Controllers that use RequestDto having List or Array Properties?
Why is there a Desarialization into a Dictionary<string, string>?
Is there a configuration I can set so the request_.Content is set to json_ and not dictionary_?
Thank you
Generated using the NSwag toolchain v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
{
"runtime": "Net80",
"documentGenerator": {
"fromDocument": {
"url": "http://localhost:1111/docs/v1/swagger",
"output": "swagger.KundenApiClient.json"
}
},
"codeGenerators": {
"openApiToCSharpClient": {
"useBaseUrl": false,
"generateBaseUrlProperty": false,
"className": "ApiClient",
"operationGenerationMode": "SingleClientFromOperationId",
//"className": "{controller}Client",
//"operationGenerationMode": "MultipleClientsFromOperationId",
"namespace": "ApiClient",
"dateType": "System.DateTime",
"dateTimeType": "System.DateTime",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.Generic.IEnumerable",
"dictionaryType": "System.Collections.Generic.Dictionary",
"arrayBaseType": "System.Collections.Generic.IEnumerable",
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"output": "../ApiClient.cs"
}
}
}