bunq / sdk_csharp

C# SDK for bunq API
MIT License
35 stars 22 forks source link

Deserializing attachment.List() fails (expects array, instead object returned) #140

Open bluewalk opened 4 years ago

bluewalk commented 4 years ago

Steps to reproduce:

  1. Query attachments, eg NoteAttachmentMasterCardAction

What should happen:

  1. Deserialize Attachment property to an AttachmentMonetaryAccountPayment as the swagger info states at e.g. https://doc.bunq.com/#/note-attachment/List_all_NoteAttachment_for_User_MonetaryAccount_RequestInquiryBatch

What happens:

  1. Throws exception like
    Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Bunq.Sdk.Model.Generated.Object.AttachmentMonetaryAccountPayment]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

Traceback

Path 'attachment.id', line 25, position 9. at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at Bunq.Sdk.Json.BunqJsonConvert.DeserializeObject[T](String value) in C:\Temp\Projects\sdk_csharp\BunqSdk\Json\BunqJsonConvert.cs:line 51 at System.Linq.Utilities.<>c__DisplayClass2_03.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.SelectIListIterator2.ToList() at Bunq.Sdk.Model.Core.BunqModel.FromJsonList[T](BunqResponseRaw responseRaw, String wrapper) in C:\Temp\Projects\sdk_csharp\BunqSdk\Model\Core\BunqModel.cs:line 110 at Bunq.Sdk.Model.Generated.Endpoint.NoteAttachmentMasterCardAction.List(Int32 mastercardActionId, Nullable1 monetaryAccountId, IDictionary2 urlParams, IDictionary`2 customHeaders) in C:\Temp\Projects\sdk_csharp\BunqSdk\Model\Generated\Endpoint\NoteAttachmentMasterCardAction.cs:line 173

SDK version and environment

Extra info:

NoteAttachmentMasterCardAction.cs and others define the attachment property as

        public List<AttachmentMonetaryAccountPayment> Attachment { get; set; }

In fact the json returns an object. Changing these properties to a simle

        public AttachmentMonetaryAccountPayment Attachment { get; set; }

fixes the issue.

This applies too all NoteAttachmentXXX classes.

bluewalk commented 4 years ago

Is there a way we can also generate the "Generated" models?

bluewalk commented 4 years ago

Unfortunately v1.14.0 doesn't fix this...

https://github.com/bunq/sdk_csharp/blob/develop/BunqSdk/Model/Generated/Endpoint/NoteAttachmentMasterCardAction.cs#L86

Seems like the swagger also states it should be a collection, but the API returns an object.

bluewalk commented 3 years ago

Unfortunately also not fixed in v1.14.1

bluewalk commented 3 years ago

@angelomelonas Unfortunately still not resolved in v1.14.18

bluewalk commented 3 years ago

When will this issue be resolved?