Jump to content
bj2cs

JSON output/result changed with upgrade

Recommended Posts

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 

 

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;

 

  • Like 1

Share this post


Link to post

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×