How do I serialize an enum value as an int?

后端 未结 6 689
长发绾君心
长发绾君心 2020-11-28 05:48

I want to serialize my enum-value as an int, but i only get the name.

Here is my (sample) class and enum:

public class Request {
    public RequestTy         


        
6条回答
  •  抹茶落季
    2020-11-28 06:44

    Since you are assigning explicit non-sequential values to the enum options I am assuming you want to be able to specify more than one value at a time (binary flags), then the accepted answer is your only option. Passing in PreBooking | PreBookingConfirmation will have an integer value of 9 and the serializer will not be able to deserialize it, casting it with a shim property however will work well. Or maybe you just missed the 3 value :)

提交回复
热议问题