Skip to content

Deserialization issue in OneOfSerializer<TOneOf> JsonConverter #20

@rrramirez

Description

@rrramirez

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions