Skip to content

A null gender property throws an exception when calling ToResult<T> #3

@mattio

Description

@mattio

While I was trying out some simple requests I found that a profile without a gender throws the following exception in the ToResult method of the Extensions class:

An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll

Additional information: Error converting value {null} to type 'ValidicCSharp.Model.GenderType'. Path 'gender', line 1, position 66.

The error was triggered by this code:

var client = new Client();
var command = new Command()
    .AuthenticationToken(user.ValidicUserAccessToken)
    .GetInformationType(CommandType.Profile);

var json = client.PerformCommand(command);
var profile = json.ToResult<Profile>();

The JSON in this scenarios was:

{
  "profile": {
    "_id": "999999999999",
    "uid": "0123456789",
    "gender": null,
    "location": null,
    "country": null,
    "birth_year": null,
    "height": null,
    "weight": null,
    "devices": {
      "fitbit": {
        "111111111": {
          "battery": "High",
          "device_version": "Flex",
          "id": "111111111",
          "last_sync_time": "2017-02-25T09:05:53.000",
          "type": "TRACKER"
        }
      }
    },
    "applications": []
  }
}

I worked around this by making GenderType on Profile nullable. I did not submit a pull request because I'm not sure if that's how you would want that handled for all customers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions