onryldz / x-superobject

Delphi Cross Platform Rapid JSON
316 stars 118 forks source link

TTime serialization #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Serialize an object with TTime property.
2. In the JSON result all is ok with a string like this "09:35:02.000".
3. But when restore this object?? I got an error with conversion fail.
Because the type cast from string will converted to double but "09:35:02.000" 
is not a valid float value :(

I got this problem at line 1924:

SetValue<Typ>(Data, MemberValue, Member, 
TValue.From<TDateTime>(IJSONData.Ancestor[Member].AsVariant)) <--- THE PROBLEM 
IS HERE

When cast TValue.From<TDateTime> the aspected variant value is double and not a 
string.

Sorry for my english. :(

Original issue reported on code.google.com by isigest...@gmail.com on 4 Oct 2014 at 10:38

GoogleCodeExporter commented 9 years ago
I solved this issue with this changes:

var
...
  LV:Variant;
...

    if IJSONData.Ancestor[Member].DataType <> dtNull then
    begin
       LV := IJSONData.Ancestor[Member].AsVariant;
       if (RType = TypeInfo(TTime)) then
         SetValue<Typ>(Data, MemberValue, Member, TValue.From<TTime>(StrToTimeDef(VarToStr(LV), EncodeTime(0, 0,0,0))))
       else
         SetValue<Typ>(Data, MemberValue, Member, TValue.From<TDateTime>(LV))
    end

Original comment by isigest...@gmail.com on 4 Oct 2014 at 10:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This issue was closed by revision r78.

Original comment by onryld...@gmail.com on 6 Oct 2014 at 9:21