-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
We have a server that delivers the following JSON (for TClient):
{
"id": 6718,
"first_name": "Hans",
"last_name": "Bauer",
"telephone": null,
"email": null,
"gender": null
}
If I read this into a TClient variable and then send this to the server again, this is translated to
{
"id": 6718,
"first_name": "Hans",
"last_name": "Bauer",
"telephone": "",
"email": "",
"gender": 0
}
which the server does not like: "0 is not a valid value for gender".
There are two solutions to this problem:
- Implement handling for
nullvalues - Provide an option to treat
nullasnot ...HasValue
While I think 1 is the correct solution, 2 can be implemented more easily by modifying OpenApiJson.pas, for example for USEDBX:
function TJsonWrapper.ObjContains(JObj: TJSONValue; const Name: string; out Value: TJSONValue): Boolean;
var
Pair: TJSONPair;
begin
Pair := TJSONObject(JObj).Get(Name);
if Assigned(Pair) then
begin
Value := Pair.JsonValue;
if Value.Null and FOptionTreatNullAsNotHasValue then
Value := nil;
end
else
Value := nil;
end;
Solution 2 would result in the following JSON, which the server happily processes:
{
"id": 6718,
"first_name": "Hans",
"last_name": "Bauer"
}
@wlandgraf What do you think?
Metadata
Metadata
Assignees
Labels
No labels