Handling null-values in float-field#132
Open
am2801 wants to merge 1 commit intofabriciocolombo:masterfrom
Open
Handling null-values in float-field#132am2801 wants to merge 1 commit intofabriciocolombo:masterfrom
am2801 wants to merge 1 commit intofabriciocolombo:masterfrom
Conversation
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.
|
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; |
|
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:
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;
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.