jsonapirestsharpspecflowjson-api-response-converter

JSON deserialization error when try to reserialize restsharp response


I am executing get API and want to retrieve a specific value from the JSON response. I want to get Job: URL value into a variable, but getting following error saying cannot deserialize Json object.

enter image description here

I am using following object model to map Json response.

class BlujayGetJobResponse
{
    public int TotalCount { get; set; }
    public string PreviousPage { get; set; }
    public string NextPage { get; set; }
    public List<Items> Items { get; set; }
}

Job and Items class objects:

 public class Job
        {
            public string Url { get; set; }
            public string Title { get; set; }
        }
        public class Items
        {
            //public List<Consignment> Consignment { get; set; }
            public string Id { get; set; }
            public string DateCreated { get; set; }
            public string Gps { get; set; }
            public string ProcessOutcome { get; set; }
            public string ProcessOutcomeInternal { get; set; }
            public string ProcessType { get; set; }
            public string ProcessTypeInternal { get; set; }
            public string CallingCard { get; set; }
            public string AdhocLocation { get; set; }
            public string ProcessOutcomeReason { get; set; }
            public string ProcessOutcomeReasonInternal { get; set; }
            public string ProcessOutcomeReasonText { get; set; }
            public string IntendedTime { get; set; }
            public string SafePlace { get; set; }
            public string DeliveredToNeighbour { get; set; }
            public string NeighbourAddress { get; set; }
            public string IdentificationDetails { get; set; }
            public List<Job> Job { get; set; }
    
    
        }

Response return from the GET API execution gives the following IResponse as content. When I try to deserialize the response to retrieve URL value getting the above error. I am new to restsharp and appreciate if anyone could help me figure this out.

JSON response:

{
  "TotalCount":2,
  "PreviousPage":null,
  "NextPage":null,
  "Items":[
    {
      "Id":"5f67fc87-4dab-4c98-bde9-8ca3ba327052",
      "DateCreated":"\/Date(1638372363000+1300)\/",
      "Gps":null,
      "ProcessOutcome":"SUC",
      "ProcessOutcomeInternal":"31",
      "ProcessType":"OFD",
      "ProcessTypeInternal":"3",
      "CallingCard":null,
      "AdhocLocation":null,
      "ProcessOutcomeReason":null,
      "ProcessOutcomeReasonInternal":null,
      "ProcessOutcomeReasonText":null,
      "IntendedTime":null,
      "SafePlace":null,
      "DeliveredToNeighbour":false,
      "NeighbourAddress":null,
      "IdentificationDetails":null,
      "Job":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Jobs/a08064c8-85fb-4e5e-8ef3-2bd24409b8d0",
        "Title":null
      },
      "Location":null,
      "Packages":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/5f67fc87-4dab-4c98-bde9-8ca3ba327052/Packages/",
        "Title":null
      },
      "Signatures":null,
      "User":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Users/126",
        "Title":null
      },
      "Link":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/5f67fc87-4dab-4c98-bde9-8ca3ba327052",
        "Title":null
      },
      "TransactionId":null
    },
    {
      "Id":"33b0c532-3ca5-4eee-a1db-d012cae064ea",
      "DateCreated":"\/Date(1638419167000+1300)\/",
      "Gps":null,
      "ProcessOutcome":"DELCRE",
      "ProcessOutcomeInternal":"330",
      "ProcessType":"DEL",
      "ProcessTypeInternal":"1",
      "CallingCard":null,
      "AdhocLocation":null,
      "ProcessOutcomeReason":null,
      "ProcessOutcomeReasonInternal":null,
      "ProcessOutcomeReasonText":null,
      "IntendedTime":null,
      "SafePlace":null,
      "DeliveredToNeighbour":false,
      "NeighbourAddress":null,
      "IdentificationDetails":null,
      "Job":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Jobs/d9b93ae1-2b37-400b-ad43-978bbad024d9",
        "Title":null
      },
      "Location":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Depots/53",
        "Title":null
      },
      "Packages":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/33b0c532-3ca5-4eee-a1db-d012cae064ea/Packages/",
        "Title":null
      },
      "Signatures":null,
      "User":null,
      "Link":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/33b0c532-3ca5-4eee-a1db-d012cae064ea",
        "Title":null
      },
      "TransactionId":null
    }
  ]
}

This is how Postman response looks like:

enter image description here

Appreciate it if you can help me out to figure out.

Really appreciate your help.

Thank you.


Solution

  • I found the resolution for this issue. Job element is an object not a list. So changing the object model as below, the error was resolved.

    public class Job
    {
        public string Url { get; set; }
        public object Title { get; set; }
    }