After update on v1.5.19 from v1.5.17 cannot serialized object.
Closed this issue · 8 comments
new HttpClient add:
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(tenderTypeAttachementApiDTO, 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_);
Error:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' because the type requires a JSON object (e.g. \name:\value) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. \name:\value) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1.
Hi, @DiegoCloud388
Could you show me your json-specification?
Hi, @unchase
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "Tender Management System WebAPI"
},
"host": "localhost:44329",
"schemes": [
"https"
],
"paths": {
"/attachements/create-tender-type-attachement": {
"post": {
"tags": [
"attachements"
],
"summary": "[EN] Create tender type attachement.\r\n[CZ] Vytvořit přílohu k typu VŘ.",
"operationId": "Attachement_CreateTenderTypeAttachement",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "tenderTypeAttachementApiDTO",
"in": "body",
"description": "",
"required": true,
"schema": {
"$ref": "#/definitions/COM.TMS.Tenders.DTO.TenderTypeAttachementApiDTO"
}
}
],
"responses": {
"202": {
"description": "Accepted"
},
"400": {
"description": "Model state is not valid."
},
"404": {
"description": "Record is not found in the database."
},
"409": {
"description": "Record violates unique constraint."
},
"500": {
"description": "Internal server error. Response body contains an exception."
}
}
}
},
I am seeing the same problem.
No changes was done in any configuration and everything worked as expected until it was updated to 1.5.19
So in my method before the update it was like this:
var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(config, settings.Value));
content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
and now its like this
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(config, 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_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
I have same csharp Client like @abjelland. I don´t undertstand why now in v1.5.19 serialized object to json and then back deserialize to dictionary???
The Connected Service based on NSwag.
This changes in generation process was added in PR #3402 - in this line and this commit.
Should create the same issue in this place.