#1 Re: mORMot 1 » JSONToObject stops deserialization if any property has null value » 2014-10-31 13:04:23

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.

JSONToObject deserialization problem when object type is null

#2 mORMot 1 » JSONToObject stops deserialization if any property has null value » 2014-10-30 16:46:57

RoneiBienert
Replies: 7

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)
property "valor" = 1000


Result with your code (property "valor" = null)
property "valor" = null


Result with my code (property "valor" = null)
property "valor" = null

#3 Re: mORMot 1 » Compatibility problem with http client and server in different version » 2014-02-26 17:25:57

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

#4 mORMot 1 » Compatibility problem with http client and server in different version » 2014-02-25 17:47:24

RoneiBienert
Replies: 3

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?

Board footer

Powered by FluxBB