You are not logged in.
Pages: 1
The json comes from a java service that allows string = null.
Even an object = null, generates this problem. the deserialization is aborted. (property "empresas1" type object)
I would like to finalize the deserialization in this case.
In method JSONToObject have the following code to treat the property with value = null.
if PInteger(result)^=NULL_LOW then begin
// nested null object
if (IsObj in [oSQLRecord,oSQLMany]) or (Kind<>tkClass) then
exit; // null expect a plain TObject
V := P^.GetOrdProp(Value);
if Obj<>nil then begin
// null -> FreeAndNil(Obj)
Obj.Free;
P^.SetOrdProp(Value,0);
end;
end else
when encountering a value = null, stop the deserialization.
I would like to finalize the deserialization. how do?
EX.:
if PInteger(result)^=NULL_LOW then begin
// nested null object
if (IsObj in [oSQLRecord,oSQLMany]) then
exit; // null expect a plain TObject
if (Kind=tkClass) then
begin
V := P^.GetOrdProp(Value);
if Obj<>nil then begin
// null -> FreeAndNil(Obj)
Obj.Free;
P^.SetOrdProp(Value,0);
end;
end;
for i:=1 to 5 do inc(From);
end else
Result with your code (property "valor" = 1000)
Result with your code (property "valor" = null)
Result with my code (property "valor" = null)
Thanks for the quick response.
His amendment partially solved my problems.
And I'm doing everything to update my client application. But for now it will be necessary.
In TServiceFactoryClient.Create method, we have this validation:
if '[' + ContractExpected + ']' <> RemoteContract then
raise EServiceException.CreateFmt (
I believe that to succeed, I have to change some more methods: ServiceResultStart, ServiceResultEnd, InternalExecuteSOAByInterface-> ServiceResult
Please see the below code and tell me what you think?
procedure TSQLRestServerURIContext.ServiceResultStart(WR: TTextWriter);
const JSONSTART: array[boolean] of RawUTF8 =
// ('{"result":[','{"result":{');
('{"result":[','{"result":[');
begin // InternalExecuteSOAByInterface has set ForceServiceResultAsJSONObject
WR.AddString(JSONSTART[ForceServiceResultAsJSONObject]);
end;
procedure TSQLRestServerURIContext.ServiceResultEnd(WR: TTextWriter; ID: integer);
const JSONSEND_WITHID: array[boolean] of RawUTF8 = ('],"id":','],"id":');
JSONSEND_NOID: array[boolean] of AnsiChar = (']',']');
//const JSONSEND_WITHID: array[boolean] of RawUTF8 = ('],"id":','},"id":');
// JSONSEND_NOID: array[boolean] of AnsiChar = (']','}');
begin // InternalExecuteSOAByInterface has set ForceServiceResultAsJSONObject
// if ID=0 then
// WR.Add(JSONSEND_NOID[ForceServiceResultAsJSONObject]) else begin
WR.AddString(JSONSEND_WITHID[ForceServiceResultAsJSONObject]);
WR.Add(ID); // only used in sicClientDriven mode
// end;
WR.Add('}');
end;
procedure TSQLRestServerURIContext.InternalExecuteSOAByInterface;
procedure ServiceResult(const Name,JSONValue: RawUTF8);
var WR: TTextWriter;
begin
WR := TJSONSerializer.CreateOwnedStream;
try
ServiceResultStart(WR);
// if ForceServiceResultAsJSONObject then
// WR.AddFieldName(Name);
WR.AddString(JSONValue);
ServiceResultEnd(WR,0);
Returns(WR.Text);
finally
WR.Free;
end;
end;
Sorry for my bad english
My client application works on the old version and it can't be updated.
My server application works on the current trunk version.
In mORMot.pas unit TServiceFactoryClient.InternalInvoke method, there is the validation:
JSONDecode (resp ['result', 'id'], Values, True);
if (Values [0] = nil) or (values [1] = nil) then begin
if aErrorMsg <> nil then
aErrorMsg ^: = 'Invalid returned JSON content';
exit;
end;
Where Value [1] is always nil. Preventing me from registering service.
Can i use client and server on different versions?
Pages: 1