2

I have an application using ASP.NET 5. I'm posting JSON and it's being deserialized to an object. I want to deserialize a string to an enum because there are a known list of possible values (paid, partially_paid,refunded,unpaid etc). A simplified version of the enum is:

[DataContract]
public enum StatusEnum
{
    [EnumMember(Value = "paid")]
    Paid,
    [EnumMember(Value = "partially_paid")]
    PartiallyPaid,
    [EnumMember(Value = "refunded")]
    Refunded,
    [EnumMember(Value = "Unpaid")]
    Unpaid
}

paid, refunded and unpaid all deserialise to the enum correctly but partially_paid doesn't and as a result the object doesn't deserialize. I assumed using the EnumMember attribute would fix this (as it would in WCF) but it doesn't make any difference.

I could, of course, make the enumeration Partially_Paid but I'd rather not as there are multiple enums that all have the same issues.

Any suggestion would be appreciated.

Mat

Mat Guthrie
  • 543
  • 1
  • 6
  • 13
  • I have a similar need https://stackoverflow.com/q/72886747/2948212 but for AspNetCore MVC in .NET 6. Did you find a solution? – diegosasw Jul 07 '22 at 14:11

0 Answers0