I am writing a console application in C#, VS2022. Where I receive a json string from Orchestrator (Uipath), try to deserialize it to an IEnumerable.
I've spent all day reading everything about this error but I can't figure out what I'm doing wrong so now I'd really like someone to help me or at least point me in the right direction.
Thanks in advanced!
This is the string:
{
"@odata.context": "https://xxxxx.com/odata/$metadata#QueueProcessingStatuses",
"@odata.count": 156,
"value": [
{
"ItemsToProcess": 1,
"ItemsInProgress": 0,
"QueueDefinitionId": 397,
"QueueDefinitionKey": "e5xxxxxx-xxxx-4c76-b145-f120d5de97dd",
"QueueDefinitionName": "_Framework2.0_TestQueue",
"QueueDefinitionDescription": null,
"QueueDefinitionAcceptAutomaticallyRetry": false,
"QueueDefinitionMaxNumberOfRetries": 0,
"QueueDefinitionEnforceUniqueReference": false,
"ProcessingMeanTime": 0,
"SuccessfulTransactionsNo": 0,
"ApplicationExceptionsNo": 0,
"BusinessExceptionsNo": 0,
"SuccessfulTransactionsProcessingTime": 0,
"ApplicationExceptionsProcessingTime": 0,
"BusinessExceptionsProcessingTime": 0,
"TotalNumberOfTransactions": 0,
"LastProcessed": "2022-03-01T08:42:10.11Z",
"ReleaseName": null,
"ReleaseId": null,
"IsProcessInCurrentFolder": null,
"SpecificDataJsonSchemaExists": false,
"OutputDataJsonSchemaExists": false,
"AnalyticsDataJsonSchemaExists": false,
"ProcessScheduleId": null,
"QueueFoldersCount": 1,
"Id": 397,
"Tags": []
}
]
}
This is the class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Text.Json;
namespace ConsoleApp1.Model
{
public class GetQueueStatusModel
{
[JsonPropertyName("@odata.context")]
public string? odatacontext { get; set; }
[JsonPropertyName("@odata.count")]
public int odatacount { get; set; }
public List<Value>? value { get; set; }
}
public class Value
{
public int ItemsToProcess { get; set; }
public int ItemsInProgress { get; set; }
public int QueueDefinitionId { get; set; }
public string? QueueDefinitionKey { get; set; }
public string? QueueDefinitionName { get; set; }
public object? QueueDefinitionDescription { get; set; }
public bool QueueDefinitionAcceptAutomaticallyRetry { get; set; }
public int QueueDefinitionMaxNumberOfRetries { get; set; }
public bool QueueDefinitionEnforceUniqueReference { get; set; }
public int ProcessingMeanTime { get; set; }
public int SuccessfulTransactionsNo { get; set; }
public int ApplicationExceptionsNo { get; set; }
public int BusinessExceptionsNo { get; set; }
public int SuccessfulTransactionsProcessingTime { get; set; }
public int ApplicationExceptionsProcessingTime { get; set; }
public int BusinessExceptionsProcessingTime { get; set; }
public int TotalNumberOfTransactions { get; set; }
public DateTime LastProcessed { get; set; }
public object? ReleaseName { get; set; }
public object? ReleaseId { get; set; }
public object? IsProcessInCurrentFolder { get; set; }
public bool SpecificDataJsonSchemaExists { get; set; }
public bool OutputDataJsonSchemaExists { get; set; }
public bool AnalyticsDataJsonSchemaExists { get; set; }
public object? ProcessScheduleId { get; set; }
public int QueueFoldersCount { get; set; }
public int Id { get; set; }
public List<object>? Tags { get; set; }
}
}
This is where i try to deserialize it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApp1.Interfaces;
using ConsoleApp1.Model;
using System.Text.Json;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace ConsoleApp1.Repository
{
internal class GetQueueStatusRepository : IGetQueueStatusRepository
{
private readonly HttpClient _httpClient;
public GetQueueStatusRepository(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<IEnumerable<GetQueueStatusModel>>GetQueueStatus()
{
var result = await _httpClient.GetAsync("odata/QueueProcessingRecords/UiPathODataSvc.RetrieveQueuesProcessingStatus");
result.EnsureSuccessStatusCode();
var response = await result.Content.ReadAsStringAsync();
return DeserializeResult<IEnumerable<GetQueueStatusModel>>(response);
}
private T? DeserializeResult<T>(string json)
{
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true
};
return JsonSerializer.Deserialize<T>(json, options);
}
}
}
Interface:
using ConsoleApp1.Model;
namespace ConsoleApp1.Interfaces
{
internal interface IGetQueueStatusRepository
{
Task<IEnumerable<GetQueueStatusModel>>GetQueueStatus();
}
}
I have tried some converter for json but i couldnt make it work for me. Alos tried some regex to edit the string but with no luck.