JSON Value for Enumerated type is invalid

I've posted this here as I only seem to get this with a WebCore App.

I have an object defined as:

TAttendance = (attNo, attCancelled, attMaybe, attYes, attAttended);

TPayMethod = (pmCash, pmCard, pmPayPal);

[Id('FId', TIdGenerator.IdentityOrSequence)]
TAttendee = class
    FId: Integer;
    FPersonId: Integer;
    FEventId: Integer;
    FAttendance: TAttendance;
    FPayment: Currency;
    FPayMethod: TPayMethod;
    [Column('PAYREF', [], 75)]
    FPayRef: String;
    [JoinColumn('PERSONID', [])]
    FPerson: Proxy<TPerson>;
  property Id: Integer read FId write FId;
  property PersonId: Integer read FPersonId write FPersonId;
  property Person: Proxy<TPerson> read FPerson write FPerson;
  property EventId: Integer read FEventId write FEventId;
  property Attendance: TAttendance read FAttendance;
  property Payment: Currency read FPayment write FPayment;
  property PayMethod: TPayMethod read FPayMethod write FPayMethod;
  property PayRef: String read FPayRef write FPayRef;

In my webcore app I have a TXDataWebDataset (AttendeeDataset). I have created the fields by adding them via the connection to the XData server and this creates MyDatasetAttendance as a TIntegerField.

I insert a record and set values as follows:

  AttendeeDatasetPersonId.Value := FPersonId;
  AttendeeDatasetEventId.Value := FEventId;
  AttendeeDatasetAttendance.Value := 4;
  AttendeeDatasetPayMethod.Value := PaidByCombo.ItemIndex;
  AttendeeDatasetPayment.Value := 10;

After this the XData server throws the following exception:

Project VCL_Buzz_XServer.exe raised exception class TJsonTypeConverter.EConvertFromJsonError with message 'Cannot read JSON property of type "TAttendance", invalid value.'.

I'm obviously doing something wrong here. Any ideas?


Indeed, for enumerated types, they are treated differently in web client, compared to desktop.

In web you don't deal with the object directly, but with JSON, and in XData specification enumerated types are send/received as strings.
The workaround here is to redeclare the field as TStringField, not integer.
We will consider adding a property "EnumAsString" in TXDataWebDataset to control that.

I just made it a plain integer field and worked around it that way.