Closed hbcondo closed 5 years ago
@hbcondo seems that responce type is not simple BPGroup but an array of BPGroup. Trt to change return type like this
var group = client.CustomRequest.Create<BPGroup, BPGroup[]>("buddypress/v1/groups", new BPGroup() { name = name, slug = slug, description = desc, creator_id = 1 }).Result;
@polushinmk, thank you for your reply. I think your suggestion worked in that the JSON serialization exception isn't being thrown using the array return type but a new exception is being thrown:
Unexpected character encountered while parsing value: {. Path '[0].description', line 1, position 93.
I guess the description
property in the response is causing this since it's a json object and WordPressPCL / Newtonsoft isn't expecting this type? If so, any suggestions on how to handle it? Thanks again.
@hbcondo you are right, this is an object instead of string. For this case you can create separate object for output. So you will have 2 objects: BPGroupInput and BPGroupOutput (for example)
client.CustomRequest.Create<BPGroupInput, BPGroupOutput[]>
description is a simple object with 1 property named "rendered"
class Description {
string rendered {get;set;}
}
Great, this approach worked; thanks again for reviewing and providing code snippets. I'm closing this issue, the exceptions experienced were not specific to WordPressPCL or Newtonsoft.
When calling the
CustomRequest.Create
method, the following exception is thrown:Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'BPGroup' 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.
Below is the code snippet that is experiencing this issue:
HTTP Request:
HTTP Response: