merge-api / merge-csharp-client

The C Sharp SDK for accessing various Merge Unified APIs
Other
2 stars 1 forks source link

Deserialization issue in OneOfSerializer<TOneOf> JsonConverter #20

Closed rrramirez closed 5 months ago

rrramirez commented 5 months ago

We are running into a deserialization issue with the new, as of 0.0.10, OneOfSerializer JsonConverter. We are fetching a list of employees using this endpoint (https://api.merge.dev/api/hris/v1/employees?expand=employments)

For further context, here is the employee record at path $.results[0]. This is all dummy test data and below is the exception we receive.

{
            "id": "ea7e23ad-da44-4b49-8493-d0917ceee856",
            "remote_id": "111",
            "created_at": "2024-06-11T18:19:06.209441Z",
            "modified_at": "2024-06-11T18:19:06.209446Z",
            "employee_number": "209",
            "company": null,
            "first_name": "Jeremy",
            "last_name": "Steel",
            "preferred_name": null,
            "display_full_name": "Jeremy Steel",
            "username": null,
            "groups": [
                "ae479784-b0d5-47ea-8196-1d2a98b18997"
            ],
            "work_email": null,
            "personal_email": "jsteel@efficientoffice.com",
            "mobile_phone_number": null,
            "employments": [
                "48568b81-5f6d-439f-a44d-d74eca86feb0"
            ],
            "home_location": "be028bcc-9679-43f0-a733-2649ecf00f08",
            "work_location": "b6c606c9-d99b-4e97-9135-82a2c1dafbef",
            "manager": null,
            "team": null,
            "pay_group": null,
            "ssn": null,
            "gender": null,
            "ethnicity": null,
            "marital_status": null,
            "date_of_birth": null,
            "hire_date": null,
            "start_date": "2024-10-29T00:00:00Z",
            "remote_created_at": null,
            "employment_status": "PENDING",
            "termination_date": null,
            "avatar": null,
            "custom_fields": null,
            "remote_was_deleted": false,
            "field_mappings": {
                "organization_defined_targets": {},
                "linked_account_defined_targets": {}
            },
            "remote_data": null
        }

An error occured deserializing the response.---> System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable1[OneOf.OneOf2[System.String,Merge.Client.Hris.Location]]. Path: $.results[0].home_location | LineNumber: 0 | BytePositionInLine: 1157.---> System.InvalidOperationException: Cannot skip tokens on partial JSON. Either get the whole payload and create a Utf8JsonReader instance where isFinalBlock is true or call TrySkip.at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_CannotSkipOnPartial()at Merge.Client.OneOfSerializer1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)at System.Text.Json.Serialization.Converters.NullableConverter1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)at System.Text.Json.Serialization.JsonCollectionConverter2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)--- End of inner exception stack trace`

dsinghvi commented 5 months ago

@rrramirez thanks for providing the JSON required to root cause the issue, we will follow up!

dsinghvi commented 5 months ago

@rrramirez -- we tested this on 0.0.10 of the SDK and found no reproduction. If it's valuable, I'm happy to hop on a call with you for 15 minutes to dive deeper.

dsinghvi commented 5 months ago

Closing this since we cannot reproduce!