#1 2021-05-21 01:27:44

wxinix
Member
Registered: 2020-09-07
Posts: 121

mORMot2, ObjectLoadJSON cannot load TDateTimeTS field

ObjectLoadJSON cannot load a TDateTimeTS field, like the following (which was saved using ObjectToJSON).

{"ID":0,"CreateTime":"2021-05-20T21:21:20.819"}

Bug?

Offline

#2 2021-05-21 12:47:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,350
Website

Re: mORMot2, ObjectLoadJSON cannot load TDateTimeTS field

TDateTimeTS ?
I guess TDateTimeMS.

Where do you think the problem comes from?

Offline

#3 2021-05-21 13:09:11

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: mORMot2, ObjectLoadJSON cannot load TDateTimeTS field

ab wrote:

TDateTimeTS ?
Where do you think the problem comes from?

Yes. I meant TDateTimeMS.

The problem of ObjectLoadJSON ended up in this part of code: mormot.core.rtti, LINE 3305-3309

function TRttiProp.SetValue(Instance: TObject; const Value: variant): boolean;
var
  k: TRttiKind;
  v64: Int64;
  f64: double;
  u: RawUtf8;
begin
  result := false; // invalid or unsupported type
  k := TypeInfo.Kind;
  if k in rkOrdinalTypes then
    if VariantToInt64(Value, v64) then
      SetInt64Value(Instance, v64)
    else
      exit
  else if k in rkStringTypes then
    if VarIsEmptyOrNull(Value) then // otherwise would set 'null' text
      SetAsString(Instance, '')
    else if VariantToUtf8(Value, u) then
      SetAsString(Instance, u)
    else
      exit
  else if k = rkFloat then
    if VariantToDouble(Value, f64) then   // <<--- the value is a DateTime string "2021-05-20T21:21:20.819", but the code is trying to convert it to a Double.
      SetFloatProp(Instance, f64)
    else
      exit
  else if k = rkVariant then
    SetVariantProp(Instance, Value)
  else
    exit;
  result := true;
end;

Last edited by wxinix (2021-05-21 13:10:02)

Offline

#4 2021-05-21 15:47:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,350
Website

Re: mORMot2, ObjectLoadJSON cannot load TDateTimeTS field

Are you using a setter method for the TDateTimeMS property?

This case was not properly handled - direct property from the field should work as expected.
I just tried to fix the problem.

Offline

#5 2021-05-21 16:21:01

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: mORMot2, ObjectLoadJSON cannot load TDateTimeTS field

Yes. The TDateTimeMS field has a setter.

Last edited by wxinix (2021-05-21 16:21:18)

Offline

Board footer

Powered by FluxBB