You are not logged in.
Pages: 1
Hello,
I'm using the mormot2 in a project. In this project I make one request to a external API. This API was returning the following object:
{
"id": 1,
"name": null,
"language_id": null,
"created_at": "2025-08-22T03:54:57.000000Z",
"updated_at": "2025-08-22T03:54:57.000000Z",
"active": true
}
And I'm using this code to get the catalog and synchronize in my application:
procedure TSyncThread.SyncCatalog;
var
Json: RawUtf8;
Valid: Boolean;
CatalogVar: variant;
CatalogModel: TCatalog;
begin
try
Valid := false;
Json := StringToUtf8(FApiConnector.getCatalog);CatalogVar := _JsonFast(Json);
try
CatalogModel := TCatalog.Create;
JsonToObject(CatalogModel, Pointer(Json), Valid);
if (Valid) then
begin
TDatabaseServer.GetInstance.getServer.CreateOrUpdate(CatalogModel);
SyncCategories(CatalogVar.categories);
end;
finally
CatalogModel.Free;
end;
except
on exception do
raise;
end;
end;
After some time, the external API was changed and introduced a new property position to the API response:
{
"id": 1,
"name": null,
"language_id": null,
"created_at": "2025-08-22T03:54:57.000000Z",
"updated_at": "2025-08-22T03:54:57.000000Z",
"active": true,
"position": 1
}
After that, my code to deserialize the JSON above stop to working and the var Valid is everytime false and the var CatalogModel dont have any other properties filled.
I did a search on forum, but I didnt find any similar case.
Is it the expected behavior? Have in the mormot2 any way to deserialize automatically a JSON and just ignore the properties that is not existing in the application class? Or in that case I will need to do the desearialization manually, property by property?
Any help is welcome.
Thank you.
Last edited by StraighFree (2026-01-08 21:16:59)
Offline
JsonToObject(CatalogModel, Pointer(Json), Valid, Nil, JSONPARSER_TOLERANTOPTIONS);
Offline
Hi tbo,
Thank you for the fast response.
I tried to use this
JsonToObject(CatalogModel, Pointer(Json), Valid, Nil, JSONPARSER_TOLERANTOPTIONS);
But I still facing the same behavior. If my application class dont have an property present in the JSON, the Valid is false and the properties on CatalogModel is not filled.
Do you have any other suggestion?
Thanks
Last edited by StraighFree (2026-01-09 18:43:26)
Offline
Hello,
I checked the mormot2 have the method CatalogModel.FillFrom(JsonString), that I can use to fill the properties for a model. In that, case we dont have the boolean value to check but we can fill the properties for a model with the value from a JSON.
Thank you for the help tbo
Offline
Offline
Pages: 1