bj2cs 1 Posted September 26, 2024 Hello, I recently upgraded code from D2010 to Alexandria. This included the MARS curiosity codebase. I have noticed that now, with endpoints that return a record as TMediaType.Application_JSON, string record data fields that are empty are completely ommitted from the resultant JSON text. Is there a way to revert back to the original behavior of returning all record fields, even blank/empty string fields? Here are the record definition, function declaration and sample results/output from before and after the upgrade: record definition: TInventoryCheckResponse = record itemkey: Integer; itemid: String; qtyavailable: Integer; function ToJSONStr: String; end; function declaration: function InventoryCheck([PathParam] ItemID: String): TInventoryCheckResponse; [POST, Path('/shipping/methods'), Produces(TMediaType.APPLICATION_JSON)] result before the upgrade: { "itemkey": 0, "itemid": "", "qtyavailable": 0 } Result after the upgrade: { "itemkey": 0, "qtyavailable": 0 } Share this post Link to post
Andrea Magni 75 Posted September 26, 2024 You can drive the serialization through the serialization options. Sincerely, Andrea Share this post Link to post
bj2cs 1 Posted September 26, 2024 @Andrea Magni Thank you sir for pointing me in the right direction. I have added the following to the server resource initialization and it appears to have resolved my issue. Quote DefaultMARSJSONSerializationOptions.SkipEmptyValues := False; 1 Share this post Link to post
Rolphy Reyes 0 Posted October 27, 2024 Hi! I have the same problem with the current version of the source code of the framework. I put this code in the ServerMainForm unit: initialization ReportMemoryLeaksOnShutdown := True; DefaultMARSJSONSerializationOptions.SkipEmptyValues := False; DefaultMARSJSONSerializationOptions.DateIsUTC := False; DefaultMARSJSONSerializationOptions.UseDisplayFormatForNumericFields := False; DefaultMARSJSONSerializationOptions.DateFormat := ISO8601; And I still can not get all the fields, the fields with empty value are completely ommitted. Share this post Link to post
Olli73 6 Posted October 27, 2024 I would try to set the options later in the code Share this post Link to post