delphi-rest-client-api icon indicating copy to clipboard operation
delphi-rest-client-api copied to clipboard

Handling null-values in float-field

Open am2801 opened this issue 5 years ago • 2 comments

I want to receive the Json-element "customfield_11111":13.0, into the structure customfield_11111: double; // jobsize That works fine, but sometimes I receive "customfield_11111":null, and get a ”Marshalling error”. With this correction I am able to receive a zero instead of a marshalling error.

am2801 avatar Dec 17 '19 13:12 am2801

Hi, @am2801, why didn't you implement code as in FromInt64() ?

    stNull:
      begin
        TValue.Make(nil, TypeInfo, Value);
        TValueData(Value).FAsSInt64 := SODefaultIntNull;
        result := true;
      end;

IgorKaplya avatar Mar 13 '20 18:03 IgorKaplya

Hi again, @am2801, I took a closer look at your request. It doesn't fail current tests and seeems to be ok, but I suggest:

  • to implement SODefaultFloatNull.
  • to add unit testing case in TestSuperobject.pas.

Please feel free to contact me with my account e-mail.

type

  TTestFloat = class(TObject)
  public
    a: Single;
    b: Double;
    d: Double;
  end;


procedure TTestSuperObjectUnMarshal.TestNullFloat;
var
  json: string;
  t: TTestFloat;
begin
  json := '{"a": 0.1234567, "b": 0.123456789012345, "d": null}';
  SODefaultFloatNull := 0.001;
  t := UnMarshal<TTestFloat>(json);
  try
    checkEquals(t.a, 0.1234567, 0.00000001, 'Failed on single');
    checkEquals(t.b, 0.123456789012345, 0.0000000000000001, 'Failed on double');
    checkEquals(t.d, SODefaultFloatNull, 0.0001);
  finally
    t.free;
  end;
end;

IgorKaplya avatar Mar 15 '20 10:03 IgorKaplya