2 kontrolör: Deserialize iç içe ıcollection <BaseType> bunun gibi bir Web Api Denetleyicisi sahip
public IHttpActionResult Create(PaymentDTO Payment)
Benim DTOs
şunlardır:public class PaymentDTO
{
public int Id { get; set; }
public string type { get; set; }
public IEnumerable<TransactionDTO> Transactions { get; set; }
}
public class TransactionDTO
{
public int Id { get; set; }
public string Description { get; set; }
public string CreateTime { get; set; }
public string UpdateTime { get; set; }
}
public class SaleDTO : TransactionDTO
{
public string Total { get; set; }
public string Currency{ get; set; }
}
public class OrderDTO : TransactionDTO
{
public string State {get;set;}
}
aşağıdaki JSON formatlı veri almak :
{ "Type": "sale", "Id": 101, "transactions": [ { "Total": "30.50", "Currency": "USD", "Description": "transaction description" } ] }
JSON.net'in veya Mülklerini temel alan IEnumerable<OrderDTO>
örneğini başlatmasını istiyorum.
Özel bir tür dönüştürücü kullanabiliyordum, ancak yalnızca Type
özelliği TransactionDTO
içeriyordu. Ancak, Type
özelliğinin üst nesnede olmasını (PaymentDTO
)
Yardımlarınız için şimdiden teşekkür ederiz.
SenPaymentDTO
sınıfı bir
custom JsonConverter
ile yapabilirsiniz