Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#11 Problem with serialized null values

open
nobody
None
5
2010-01-04
2010-01-04
Anonymous
No

I get an EInvalidCast exception with message 'Invalid class typecast', in TlkJSONobject.getString(idx: Integer), when trying to get a string that has been serialized with null value. I think you might get the same error with other types too: getInt(), getDouble()...

I noticed that it handles nil but not null values. But my application communicates with a java application which serializes null values as null.

Code to reproduce problem (tested with LkJSON v1.07):

function TForm1.FromJSON(Json: String): String;
var
js : TlkJSONobject;
begin
Result := '';
js := nil;
try
js := TlkJSON.ParseText(Json) as TlkJSONobject;
if Assigned(js) then
Result := js.getString('description');
finally
js.Free;
end;
end;

The following calls works:
FromJSON('{"description":"Bla bla"}');
FromJSON('{"description":nil}');

This call fails:
FromJSON('{"description":null}');

Discussion