Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling null-values in float-field #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

am2801
Copy link

@am2801 am2801 commented Dec 17, 2019

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.

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.
@IgorKaplya
Copy link

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
Copy link

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;

Copy link

@IgorKaplya IgorKaplya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See conversation pn PR #132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants