cancel
Showing results for 
Search instead for 
Did you mean: 

How to format edm.decimals in POST/PUT/PATCH?

klaus_kopecz
Participant

I have a follow on question to the already answered question https://answers.sap.com/questions/12696596/not-able-to-create-entries-with-decimal-attributes.html.

It's about formatting edm.decimal in http request bodies when sending requests to CAP services. Deviating from the OData specification, this has to be done as JSON-Strings. Fine. However, I've found tha this is not enough to make things work. Consider this request:

PATCH   http://localhost:4004/admin/Products(101) 
Content-Type: application/json

{ 
    "price": "12.13"
}

where price is Decimal(9,2). This results in an error response (cds version 3.31.1 on Node.js):

"Error while deserializing payload; consider using parameter IEEE754Compatible=true in content-type with adjusted formatting. An error occurred during deserialization of the entity. A JSON number is not supported as Edm.Decimal value."

Now, extending the Content-Type header to

Content-Type: application/json;IEEE754Compatible=true

makes the request working correctly!

My question is: Is this IEEE header parameter the official recommendation by the CAP team? Is this documented somewhere (cannot find it in cap.cloud.sap at least)? Are there more consequences when setting this IEEE-parameter?

Thanks,

Klaus

Accepted Solutions (0)

Answers (1)

Answers (1)

oliver_heinrich
Explorer

Hi Klaus,

for JavaScript and Node.js it is the recommendation to use always the IEEE753Compatible=true format parameter. This will definitely make applications more robust as EDM.Decimal supports a larger value range then Javascript numbers and if you do JSON.parse() for request payloads then EDM.Decimal values will not be cut off .

Regards Oliver

gregorw
Active Contributor
0 Kudos

Maybe peter.muessig can do something that SAPUI5 does use that also by default? Currently searching for IEEE753Compatible in the SAPUI5 documentation doesn't return any link.

oliver_heinrich
Explorer
0 Kudos

Hi Gregor,

there was a typo in my comment I meant the format parameter IEEE754Compatible. I think you can also contact Mathias Uhlmann from UI5 who takes care for the OData integration.

klaus_kopecz
Participant
0 Kudos

There should be an official guideline somewhere (documentation?) which states that we have to set IEEE754Compatible=true.

gregorw : Maybe you can share any results of your research here. Thanks

Regards

gregorw
Active Contributor
0 Kudos

Hi klaus.kopecz and oliver.heinrich,

@Oliver: But even with IEEE754Compatible the search result is empty.

@Klaus: I've faced this issue in January: OData V2 Proxy issue with Decimal data type #24. With the help of oliver.klemenz this was fixed in the OData V2 Proxy.

Best regards
Gregor

mathias_uhlmann
Advisor
Advisor
0 Kudos

Hi oliver.heinrich and klaus.kopecz ,

the v4.ODataModel of SAPUI5 provides IEEE754Compatible=true:

"Content-Type" : "application/json;charset=UTF-8;IEEE754Compatible=true"

"Accept" : "application/json;odata.metadata=minimal;IEEE754Compatible=true"

Best regards

Mathias.

Shubham_M
Participant
0 Kudos

Hi oliver.heinrich , klaus.kopecz, mathias.uhlmann ,

I am trying to fire a GET service from the CAP layer to our backend gateway system but the response I am getting is truncating the zeroes after decimal places and converting to whole numbers. ( 12.00 is converted to 12 while 12.13 is correctly coming as 12.13)

I am trying to pass below in the header but it gives me the error "The resource identified by the request is only capable of generating response entities which have content characteristics no acceptable according to the accept headers sent in the request.

"Content-Type" : "application/json;charset=UTF-8;IEEE754Compatible=true"

"Accept" : "application/json;odata.metadata=minimal;IEEE754Compatible=true"

oliver_heinrich
Explorer
0 Kudos

Hi Shubham,

I'm a long time not in the project anymore. I think the right contacts to answer your question are:

CAP: vansyckel and

Gateway ABAP: bernhard.grusie

Regards Oliver

Shubham_M
Participant
0 Kudos

Hi vansyckel,

Can you please help me out on the following issue.

I am trying to fire a GET service from the CAP layer to our backend gateway system but the response I am getting is truncating the zeroes after decimal places and converting to whole numbers. ( 12.00 is converted to 12 while 12.13 is correctly coming as 12.13)

I am trying to pass below in the header but it gives me the error "The resource identified by the request is only capable of generating response entities which have content characteristics no acceptable according to the accept headers sent in the request.

"Content-Type" : "application/json;charset=UTF-8;IEEE754Compatible=true"

"Accept" : "application/json;odata.metadata=minimal;IEEE754Compatible=true"

vansyckel
Advisor
Advisor
0 Kudos

Hi,

So your backend gateway rejects the your accept header? Then there's nothing you can do in your CAP app other than format manually in an after handler... Have you tried with Postman et al.? Maybe the odata.metadata=minimal is the issue?

Best,
Sebastian

Shubham_M
Participant
0 Kudos

Hi vansyckel

Yes I tried in postman.If I pass custom header 'Content-Type: application/json;IEEE754Compatible=true' it gives us correct value.But giving the same in CAP doesn't have any impact.ThanksSujit
vansyckel
Advisor
Advisor
0 Kudos

Hi Sujit,

CAP supports the header (see this test). Do you mean that the header is not forwarded to the remote service? That you can achieve via out send API (see this and this).

Best,
Sebastian