estoy teniendo duda de como consumir un API HAL, ya que es la primera vez que trabajo con esta tecnologia y la forma que utilizaba para deserializar un json era con Newtonsoft.Json pero no he podido realizarlo.
Les comparto parte de la estructura del json que me regresa el API para ver si ne podrian orientar en este proceso.
{
"_embedded": {
"tasks": [
{
"deleted": false,
"uniqueCode": "b870314d-3b34",
"companyCode": "b6d8b23e-e696",
"lastModifiedDate": "2022-09-19T16:54:02.787+00:00",
"createdDate": "2022-09-19T16:54:02.787+00:00",
"createdBy": "b425c4fb-2d47315d2938",
"purchase": {
"deleted": false,
"uniqueCode": "3dd867b9-272b",
"companyCode": "b6d8b23e-e696",
"lastModifiedDate": "2022-09-19T16:54:18.863+00:00",
"createdDate": "2022-09-19T16:41:33.362+00:00",
"createdBy": "PROCESSOR",
"company": {
"uniqueCode": "b6d8b23e-e696",
"name": "MINI",
"logoURL": "https://s3.amazonaws.com/ejemplo",
"governmentId": "MMMMM",
"hasChildren": false
},
"_links": {
"self": {
"href": "https://app.ejemplo.com/api/purchases/3dd867b9-272b"
},
"selectable-budgets": {
"href": "https://app.ejemplo.com/api/purchases/3dd867b9-272b/selectable-budgets"
},
"selectable-categories": {
"href": "https://app.ejemplo.com/api/purchases/3dd867b9-272b/selectable-categories"
},
"patch": {
"href": "https://app.ejemplo.com/api/purchases/3dd867b9-272b/version/5"
},
"thumbnail": {
"href": "https://app.ejemplo.com/api/files/ae491204-1300/thumbnail/bytes"
},
"purchase-files": {
"href": "https://app.ejemplo.com/api/purchases/3dd867b9-272b/files"
}
}
},
"status": "ACTIVE",
"payer": {
"links": {
"self": {
"href": "https://app.ejemplo.com/api/people/b425c4fb-3e61"
}
},
"deleted": false,
"uniqueCode": "b425c4fb-3e61",
"companyCode": "b6d8b23e-e696",
"company": {
"uniqueCode": "b6d8b23e-e696",
"name": "MINI",
"logoURL": "https://s3.amazonaws.com/ejemplo/165f4.png",
"governmentId": "MMMMMMMMMM",
"hasChildren": false
},
"name": "NAME",
"lastName": "LASTNAME",
"email": "user@ejemplo.com",
"cardOwner": false,
"costCenter": {
"deleted": false,
"uniqueCode": "3a7f69cd-c6184",
"companyCode": "b6d8b23e-e696",
"lastModifiedDate": "2022-07-26T21:12:09.479Z",
"createdDate": "2022-07-26T21:12:09.479Z",
"createdBy": "4adabe2d-a5b5",
"company": {
"uniqueCode": "b6d8b23e-e696",
"name": "MINI",
"logoURL": "https://s3.amazonaws.com/ejemplo/d84538165f4.png",
"governmentId": "MMMMMMMM",
"hasChildren": false
},
"name": "NAME"
},
"active": true,
"fullName": "FULLNAME",
"companyCodes": [
"b6d8b23e-e696"
],
"initials": "MM",
"_links": {
"self": {
"href": "https://app.ejemplo.com/api/people/b425c4fb-3e61"
}
}
},
"_links": {
"self": {
"href": "https://app.ejemplo.com/api/ejemplo/b870314d-3b34"
}
}
},
{
"deleted": false,
"uniqueCode": "f0f16385-b395",
"companyCode": "af283904-ff63",
"lastModifiedDate": "2022-09-19T16:52:02.714+00:00",
"createdDate": "2022-09-19T16:52:02.714+00:00",
"createdBy": "7c782642-9af3",
"purchase": {
"deleted": false,
"uniqueCode": "dbb5d272-e4db",
"companyCode": "af283904-ff63",
"lastModifiedDate": "2022-09-19T16:52:02.415+00:00",
"createdDate": "2022-09-16T18:24:50.832+00:00",
"createdBy": "PROCESSOR",
"company": {
"uniqueCode": "af283904-ff63",
"name": "NAME",
"logoURL": "https://s3.amazonaws.com/ejemplo/5a4b8273593a20461b.png",
"governmentId": "MMMMMMMMM",
"hasChildren": false
},
"source": "PROCESSOR",
"description": "DESCRIPTION",
"version": 2,
"seller": {
"name": "name",
"merchantCode": "0000",
"category": "CATEGORIA",
"categoryDescription": "ESTACION"
},
"payment": {
"transactionId": "15d7ad12-4bb4",
"traceId": "000000000000",
"status": "PROCESSED",
"mode": "PHYSICAL_CARD",
"confirmationCode": "6b8ca2b9-108b",
"payerCompanyLegalId": "MMMMMMMMM",
"payerCompanyName": "MMMMMMMMMM",
"payerPersonCode": "7c782642-9af3",
"payerFullName": "FULLNAME",
"payerLegalId": "0000000",
"paymentCardCode": "efd137d0-815e",
"paymentCardLast4Digits": "0000",
"date": "2022-09-16T18:24:49.891Z",
"ticketFiles": [
{
"file": {
"filename": "2022-09-19-t-16-52-00-800-z.jpg",
"uniqueCode": "e1f714b8-6ec5",
"_links": {
"bytes": {
"href": "https://app.EJEMPLO.com/api/files/e1f714b8/bytes"
}
}
}
},
{
"file": {
"filename": "2022-09-19-t-16-52-01-290-z.jpg",
"uniqueCode": "d5cb2db8-2500",
"_links": {
"bytes": {
"href": "https://app.mendel.com/api/files/d5cb2db8/bytes"
}
}
}
}
],
"channel": "PHYSICAL",
"locationType": "LOCAL",
"receiptAttached": true,
"ticketAttached": true
},
"budgetCode": "9433af2e-374c",
"budgetName": "SERVICE",
"readyForBudgeting": true,
"amount": 150.45,
"confirmedAmount": 150.45,
"effectiveConfirmedAmount": 150.45,
"sign": -1,
"currency": {
"code": "MXN",
"minDecimalPlaces": 2,
"maxDecimalPlaces": 2
},
"status": "CONFIRMED",
"cancelled": false,
"type": "PURCHASE",
"summaryStatus": "AUTHORIZED_PAYMENT",
"expenseCategory": {
"code": "428f22b8-b636",
"description": "DESCRIPTION"
},
"countryCode": "MX",
"city": "MX",
"reviewRequired": false,
"invoiceable": true,
"adjustmentOrRefundParent": false,
"foreignPurchase": false,
"signedAmount": 150.45,
"shortId": "ABCDEFG",
"_links": {
"self": {
"href": "https://app.ejemplo.com/api/ejemplo/dbb5d272-e4db"
},
"selectable-budgets": {
"href": "https://app.ejemplo.com/api/ejemplo/dbb5d272-e4db/selectable-budgets"
},
"selectable-categories": {
"href": "https://app.ejemplo.com/api/ejemplo/dbb5d272-e4db/selectable-categories"
},
"patch": {
"href": "https://app.ejemplo.com/api/ejemplo/dbb5d272-e4db/version/2"
},
"thumbnail": {
"href": "https://app.ejemplo.com/api/ejemplo/e1f714b8/thumbnail/bytes"
},
"purchase-files": {
"href": "https://app.ejemplo.com/api/ejemplo/dbb5d272-e4db/files"
}
}
},
"status": "ACTIVE",
"payer": {
"links": {
"self": {
"href": "https://app.ejemplo.com/api/ejemplo/7c782642-9af3"
}
},
"deleted": false,
"uniqueCode": "7c782642-9af3",
"companyCode": "af283904-ff63",
"company": {
"uniqueCode": "af283904-ff63",
"name": "MMMMMMM",
"logoURL": "https://s3.amazonaws.com/ejemplo/20461b.png",
"governmentId": "MMMMMMMMM",
"hasChildren": false
},
"name": "NAME",
"lastName": "LASTNAME",
"email": "user@ejemplo.com",
"cardOwner": false,
"active": true,
"fullName": "FULLNAME",
"companyCodes": [
"af283904-ff63"
],
"initials": "MM",
"_links": {
"self": {
"href": "https://app.ejemplo.com/api/ejemplo/7c782642-9af3"
}
}
},
"_links": {
"self": {
"href": "https://app.ejemplo.com/api/ejemplo/f0f16385-b395"
}
}
}
]
},
"_links": {
"first": {
"href": "https://app.ejemplo.com/api/ejemplo/?status=ACTIVE&sort%5B0%5D.property=purchase.payment.lastModifiedDate&sort%5B0%5D.direction=DESC&status%5B%5D=ACTIVE&page=0&size=10&sort=purchase.payment.lastModifiedDate,desc"
},
"self": {
"href": "https://app.ejemplo.com/api/ejemplo/?status=ACTIVE&sort%5B0%5D.property=purchase.payment.lastModifiedDate&sort%5B0%5D.direction=DESC&status%5B%5D=ACTIVE&page=0&size=10&sort=purchase.payment.lastModifiedDate,desc"
},
"next": {
"href": "https://app.ejemplo.com/api/ejemplo/?status=ACTIVE&sort%5B0%5D.property=purchase.payment.lastModifiedDate&sort%5B0%5D.direction=DESC&status%5B%5D=ACTIVE&page=1&size=10&sort=purchase.payment.lastModifiedDate,desc"
},
"last": {
"href": "https://app.ejemplo.com/api/ejemplo/?status=ACTIVE&sort%5B0%5D.property=purchase.payment.lastModifiedDate&sort%5B0%5D.direction=DESC&status%5B%5D=ACTIVE&page=90&size=10&sort=purchase.payment.lastModifiedDate,desc"
}
},
"page": {
"size": 10,
"totalElements": 90,
"totalPages": 9,
"number": 0
}
}
Agradeceria cualquier sugerencia o libreria para pasarlo a un modelo. y de ahi a mi vista, ya que no he logrado pasarlo como si fuera un Json normal, ya que con IEnumerable ni como List lo reconoce, y produce una excepción.
Este es el modelo:
using Newtonsoft.Json;
namespace Web.Models
{
public class Tareas
{
[JsonProperty(PropertyName = "_embedded")]
public List<Embedded> embedded { get; set; }
[JsonProperty(PropertyName = "_links")]
public List<Links> _links { get; set; } = null!;
[JsonProperty(PropertyName = "page")]
public List<Page> page { get; set; } = null!;
}
public class Embedded
{
[JsonProperty(PropertyName = "tasks")]
public Tasks tasks { get; set; } = null!;
}
public class Tasks
{
public string deleted { get; set; } = null!;
public string uniqueCode { get; set; } = null!;
public string companyCode { get; set; } = null!;
public DateTime lastModifiedDate { get; set; }
public DateTime createdDate { get; set; }
public string createdBy { get; set; } = null!;
public Purchase purchase { get; set; } = null!;
public string status { get; set; } = null!;
public Payer payer { get; set; } = null!;
}
public class Purchase
{
public string deleted { get; set; } = null!;
public string uniqueCode { get; set; } = null!;
public string companyCode { get; set; } = null!;
public DateTime lastModifiedDate { get; set; }
public DateTime createdDate { get; set; }
public string createdBy { get; set; } = null!;
public List<Company> company { get; set; } = null!;
public string source { get; set; } = null!;
public string description { get; set; } = null!;
public string version { get; set; } = null!;
public List<Seller> seller { get; set; } = null!;
public List<Payment> payment { get; set; } = null!;
public string budgetCode { get; set; } = null!;
public string budgetName { get; set; } = null!;
public string readyForBudgeting { get; set; } = null!;
public int amount { get; set; }
public int confirmedAmount { get; set; }
public int effectiveConfirmedAmount { get; set; }
public int sign { get; set; }
public List<Currency> currency { get; set; } = null!;
public string status { get; set; } = null!;
public string cancelled { get; set; } = null!;
public string type { get; set; } = null!;
public string summaryStatus { get; set; } = null!;
public List<ExpenseCategory> expenseCategory { get; set; } = null!;
public string countryCode { get; set; } = null!;
public string city { get; set; } = null!;
public string costCenterCode { get; set; } = null!;
public string costCenterName { get; set; } = null!;
public string reviewRequired { get; set; } = null!;
public string invoiceable { get; set; } = null!;
public string adjustmentOrRefundParent { get; set; } = null!;
public string foreignPurchase { get; set; } = null!;
public int signedAmount { get; set; }
public string shortId { get; set; } = null!;
[JsonProperty("_Links")]
public LInks Llinks { get; set; } = null!;
}
public class Company
{
public string uniqueCode { get; set; } = null!;
public string name { get; set; } = null!;
public string logoURL { get; set; } = null!;
public string governmentId { get; set; } = null!;
public string hasChildren { get; set; } = null!;
}
public class Seller
{
public string name { get; set; } = null!;
public int merchantCode { get; set; }
public string category { get; set; } = null!;
public string categoryDescription { get; set; } = null!;
}
public class Payment
{
public string transactionId { get; set; } = null!;
public string traceId { get; set; } = null!;
public string status { get; set; } = null!;
public string mode { get; set; } = null!;
public string confirmationCode { get; set; } = null!;
public string payerCompanyLegalId { get; set; } = null!;
public string payerCompanyName { get; set; } = null!;
public string payerPersonCode { get; set; } = null!;
public string payerFullName { get; set; } = null!;
public string payerLegalId { get; set; } = null!;
public string paymentCardCode { get; set; } = null!;
public int paymentCardLast4Digits { get; set; }
public DateTime date { get; set; }
public List<TicketFiles> ticketFiles { get; set; } = null!;
public string channel { get; set; } = null!;
public string locationType { get; set; } = null!;
public string receiptAttached { get; set; } = null!;
public string ticketAttached { get; set; } = null!;
}
public class TicketFiles
{
public List<File> file { get; set; } = null!;
}
public class File
{
public string filename { get; set; } = null!;
public string uniqueCode { get; set; } = null!;
[JsonProperty("_Links")]
public List<Links> links { get; set; } = null!;
}
public class Links
{
public List<Bytes> bytes { get; set; } = null!;
}
public class Bytes
{
public string href { get; set; } = null!;
}
public class Currency
{
public string code { get; set; } = null!;
public int minDecimalPlaces { get; set; }
public int maxDecimalPlaces { get; set; }
}
public class ExpenseCategory
{
public string code { get; set; } = null!;
public string description { get; set; } = null!;
}
public class LInks
{
public List<Bytes> self { get; set; } = null!;
}
public class Payer
{
}
public class Page
{
public int size { get; set; }
public int totalElements { get; set; }
public int totalPages { get; set; }
public int number { get; set; }
}
}
Saludos y gracias comunidad.