delphi - SuperObject cannot handle null string -
some json serializers return null
empty string datafield, e.g.
{ "searchtext": null, "moretext": "contains something", "bookdate": 1377468000000, "empid": 12345, "listtype": 1 }
i'm using superobject create isuperobject:
var fjsonrequest: isuperobject; fjsonrequest := so(request.content); // webservice request
this returns object string containing text 'null'
.
obviously because superobject not care quotes ("searchtext": a
gives same results "searchtext": "a"
).
before dive 980-line tokenizer routine, 1 have solution?
i'm thinking along lines (either/or):
leave null datafield out of json object
return empty string
if else fails still do
fjsonrequest := so(stringreplace(request.content,': null,',':,',[rfreplaceall]));
because need handle requests coming app 1 of our developers, that's not foolproof.
(no, cannot suppress null
because there's bug in way mono handles datacontract.)
btw i'm experiencing the behaviour mentioned here, in part of superobject code, workaround not job.
the official 1.2.4 zip file in download section http://code.google.com/p/superobject/downloads/list dates 2010, individual files in http://code.google.com/p/superobject/source/browse have updates until oct 2012.
if go last url , click on download zip
can retrieve them.
these updated files let use special case null
.
the code still 'forgiving' if omit quotes around string value:
{ "bookdate": 1377554400000, "searchtext": a, "listtype": 1 }
but handles special case
{ "bookdate": 1377554400000, "searchtext": null, "listtype": 1 }
as if was
{ "bookdate": 1377554400000, "searchtext": , "listtype": 1 }
or
{ "bookdate": 1377554400000, "listtype": 1 }
[do not accidentally type nil
or null
]
this release supports until ver230 (delphi xe2) [note 'official' 1.2.4 did not compile on more recent delphi versions], later versions of delphi you'll have patch compiler directives.
it fixes following:
when floating point value happened have exact integer value, json have trailing period:
{ "floatingpointvalue": 4. }
this fixed:
{ "floatingpointvalue": 4 }
errors in datetime conversions happening around switch daylight savings time in leapyears - yes, obscure.
there error in code section surrounded{$ifdef windowsnt_compatibility}
note still defined default, suggest disable define , e.g. {.$ifdef windowsnt_compatibility}
[who needs run on windows nt nowadays?], lets os handle datetime conversions:
{$else} function tzspecificlocaltimetosystemtime( lptimezoneinformation: ptimezoneinformation; lplocaltime, lpuniversaltime: psystemtime): bool; stdcall; external 'kernel32.dll'; function systemtimetotzspecificlocaltime( lptimezoneinformation: ptimezoneinformation; lpuniversaltime, lplocaltime: psystemtime): bool; stdcall; external 'kernel32.dll'; {$endif}
Comments
Post a Comment