merge-api / merge-hris-csharp-net

The C# API Client for the Merge HRIS API.
Other
3 stars 2 forks source link

Deserialization exception when using expand #4

Closed benzara-tahar closed 2 years ago

benzara-tahar commented 3 years ago

Hello,

When using the expand parameter in the EmployeeApi , I have this exception

      Merge.HRISClient.Client.ApiException
        HResult=0x80131500
        Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Guid' because the type requires a JSON primitive value (e.g. string, number, boolean, null) to deserialize correctly.
      To fix this error either change the JSON to a JSON primitive value (e.g. string, number, boolean, null) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
      Path 'results[0].employments[0].id', line 1, position 365.
        Source=Merge.HRISClient
        StackTrace:
         at Merge.HRISClient.Client.CustomJsonCodec.Deserialize(IRestResponse response, Type type) in D:\_dev\qomben\qomben-datagenerator\merge-hris-csharp-net-main\src\Merge.HRISClient\Client\ApiClient.cs:line 146
         at Merge.HRISClient.Client.CustomJsonCodec.Deserialize[T](IRestResponse response) in D:\_dev\qomben\qomben-datagenerator\merge-hris-csharp-net-main\src\Merge.HRISClient\Client\ApiClient.cs:line 87
         at RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw)

Most likely because the response contains nested array of Employment, and the corresponding model is just an array of Guid.

here is a sample code

        var employees = _employeesApi
                        .EmployeesList(_configuration.XAccountToken,
                        companyId: null,
                        createdAfter: null,
                        createdBefore: null,
                        cursor,
                        expand: "employments",
                        includeRemoteData,
                        includeSensitiveFields,
                        managerId: null,
                        modifiedAfter: null,
                        modifiedBefore: null,
                        pageSize,
                        remoteId: null,
                        teamId: null,
                        workLocationId: null);

it will be great if you can fix that

leewang0 commented 2 years ago

We do not currently plan to support expands parameter at this time, this may change in the future.