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:

[Enumeration(TEnumMappingType.emInteger)]
TAttendance = (attNo, attCancelled, attMaybe, attYes, attAttended);

[Enumeration(TEnumMappingType.emInteger)]
TPayMethod = (pmCash, pmCard, pmPayPal);

[Entity]
[Automapping]
[Id('FId', TIdGenerator.IdentityOrSequence)]
TAttendee = class
private
    [Column('ATTENDEEID')]
    FId: Integer;
    [Column('PERSONID')]
    FPersonId: Integer;
    [Column('EVENTID')]
    FEventId: Integer;
    [Column('ATTENDANCE')]
    FAttendance: TAttendance;
    [Column('PAYMENT')]
    FPayment: Currency;
    [Column('PAYMETHOD')]
    FPayMethod: TPayMethod;
    [Column('PAYREF', [], 75)]
    FPayRef: String;
    [Association([TAssociationProp.Lazy],CascadeTypeAllButRemove)]
    [JoinColumn('PERSONID', [])]
    FPerson: Proxy<TPerson>;
public
  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;
end;

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:

  AttendeeDataset.Close;
  AttendeeDataset.SetJsonData('{}');
  AttendeeDataset.Open;
  AttendeeDataset.Insert;
  AttendeeDatasetPersonId.Value := FPersonId;
  AttendeeDatasetEventId.Value := FEventId;
  AttendeeDatasetAttendance.Value := 4;
  AttendeeDatasetPayMethod.Value := PaidByCombo.ItemIndex;
  AttendeeDatasetPayment.Value := 10;
  AttendeeDataset.Post;
  AttendeeDataset.ApplyUpdates; 

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?

Russell

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.