You are not logged in.
Hello,
I'm trying to serialize a JSON into record with nested one, but RecordLoadJSON returns FALSE.
JSON (body.json file) is like this:
{
"integrationId":19,
"token":{
"accessToken":"eyJhbGciOiJSUzI1NiIsInR5c",
"createdIn":"2020-01-21 09:28:44",
"expiresIn":"2024-12-25 09:28:44"
},
"success":true,
"message":null
}
Then, I have TTokenResponse and TLoginResponse:
type
TTokenResponse = packed record
accessToken: RawUTF8;
createdIn: TDateTime;
expiresIn: TDateTime;
end;
TLoginResponse = packed record
integrationId: Integer;
token: TTokenResponse;
sucess: boolean;
message: RawUTF8;
end;
initialization
TTextWriter.RegisterCustomJSONSerializerFromText([
TypeInfo(TTokenResponse), 'accessToken:RawUTF8 createdIn,expiresIn:TDateTime',
TypeInfo(TLoginResponse), 'integrationId:Integer token:TTokenResponse sucess:boolean message:RawUTF8'
]);
If I remove "success" field from both (JSON and record), it works.
I'm using last version of mORMot but compiling on Delphi 7.
For testing, could be like this:
function Login: TLoginResponse;
var
l: TRawUTF8List;
begin
RecordZero(result, TypeInfo(TLoginResponse));
l := TRawUTF8List.Create;
try
l.LoadFromFile('body.json');
if not RecordLoadJSON(result, l.Text, TypeInfo(TLoginResponse)) then
raise Exception.Create('Invalid...');
finally
l.Free;
end;
end;
best regards.
Last edited by mdbs99 (2020-01-21 14:51:04)
Offline
You have a typo in your code.
In the text description (and record type definition), it is sucess:boolean (single C) whereas in the JSON it is "success" (two C).
Offline