#1 2024-10-28 16:26:11

ertank
Member
Registered: 2016-03-16
Posts: 168

JSON de-serialization - string quoted numbers

Hello,

There is this java web service which is requesting and responding using the identical JSON format.

I have below record definition. That record is serialized and sent to the web service. There is no problem and it consumes it.

  THuginTPSSaleOrderSaleItem = packed record
    Quantity: Double;
    Amount: Double;
    PLUNo: Integer;
    DepartmentId: Integer;
    VatRate: Double;
  end;

But, the web service is responding something like below

    {
      "Quantity": "2.00",
      "Amount": "10.00",
      "PLUNo": 1,
      "DepartmentId": 1,
      "VatRate": 0,
    }

As you can see the web service respond has some numbers as double quoted (aka string).

I wonder if mORMot2 can de-serialize these numbers in double data type as defined in the record.
If it is possible, I do appreciate a small RecordLoadJson() example showing how I can build necessary parameters and pass them to the function.

Thanks & Regards,
Ertan

P.S. Both record and json examples are greatly minimized for keeping this post short.

Offline

#2 2024-10-28 17:05:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,684
Website

Re: JSON de-serialization - string quoted numbers

I can't reproduce it here.

Please provide a small reproducible example, in a separate gist or link.
(not in the forum directly)

Offline

#3 2024-10-28 17:59:52

zen010101
Member
Registered: 2024-06-15
Posts: 70

Re: JSON de-serialization - string quoted numbers

ertank wrote:

I wonder if mORMot2 can de-serialize these numbers in double data type as defined in the record.
If it is possible, I do appreciate a small RecordLoadJson() example showing how I can build necessary parameters and pass them to the function.

mORMot can deal with such formatted JSON string. Here is demonstration code for using RecordLoadJson() to process it.

https://gist.github.com/zen010101/75acf … 1c7476285f

Offline

#4 2024-10-28 18:19:45

ertank
Member
Registered: 2016-03-16
Posts: 168

Re: JSON de-serialization - string quoted numbers

I didn't know that mORMot2 has such ability and also that it is turned on by default.
I spotted that I missed several breaking format differences in the web service response.

Sorry about the noise.

Last edited by ertank (2024-10-28 18:29:01)

Offline

Board footer

Powered by FluxBB