This is a migrated thread and some comments may be shown as answers.

Number format incorrect in PUT and POST operation

3 Answers 229 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Olivier
Top achievements
Rank 1
Olivier asked on 29 Jun 2018, 06:54 AM

Hello

In PUT and POST operation all number properties of my entity are sent in string format. In my GET operation, I receive my entity with correct value, but when I send my entity, my datasource convert number properties in string.

My datasource definition :

var _FrmTest_dtTtOrigineGeographique = new kendo.data.DataSource({
            type: "odata-v4",
            content: "json",
            transport: {
                read: {
                    url: "https://localhost:9443/odata/EntiteTtOrigineGeographiques",
                },
                update: {                     
                    url: function (data) { return "https://localhost:9443/odata/EntiteTtOrigineGeographiques(" + data.IdTtOrigineGeographique + ")" },
                }
                 
            },
            schema: {
                model: {
                    id: "IdTtOrigineGeographique",
                    fields: {
                        IdTtOrigineGeographique: {
                            type: "number",
                            editable: false,
                        },
                        StrLibelle: {
                            type: "string"
                        },

                        Pourcentage: {

                             type: "number"

                        }

                    }
                }
            },
            error: function (e) {
                console.log(e.xhr);
            },
            filter: {
                logic: "and",
                filters: [
                    { field: "IdTtOrigineGeographique", operator: "eq", value: _idTtOrigineGeographiqueSelect }]
            },
            serverFiltering: true,
            serverSorting: true
        });

With GET operation, I receive my entity like this

{"@odata.context":"https://localhost:9443/odata/$metadata#EntiteTtOrigineGeographiques","@odata.count":1,"value":[{"IdTtOrigineGeographique":5,"StrLibelle":"Autres départements", "Pourcentage": 4.55}]}

But when I update my entity and I call sync method, my datasource send my entity like this :

{"IdTtOrigineGeographique":"5","StrLibelle":"Autres département","Pourcentage":"4.55"}

I verify JSON.stringify() and kendo.stringify() functions and my entity is correctly serialize

For integer property it's not blocking because my webservice convert automatically string to integer. But with float (ex : 4.55), I have a exception and my entity it's not deserialize.

Can you help me ? Thanks in advance

Arnaud

3 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 03 Jul 2018, 08:05 AM
Hello Arnaud,

As you have correctly noticed, on Update or Create, the current implementation of the odata v4 transport type of the DataSource will internally stringify the numeric values in the item. In order to alter this behaviour of the utility you could implement a parameterMap function for the transport:
var _FrmTest_dtTtOrigineGeographique = new kendo.data.DataSource({
    type: "odata-v4",
    content: "json",
    transport: {
        read: {
            url: "https://localhost:9443/odata/EntiteTtOrigineGeographiques",
        },
        update: {                    
            url: function (data) { return "https://localhost:9443/odata/EntiteTtOrigineGeographiques(" + data.IdTtOrigineGeographique + ")" },
        }
          
    },
    parameterMap: function(options, operation) {
        if (operation !== "read" && options) {
            return kendo.stringify(options);
        }
    }
...

I hope that this helps.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Olivier
Top achievements
Rank 1
answered on 03 Jul 2018, 09:47 AM

Hello Veselin

Thanks, that's work. I just add a line (for read filters). But why it's not normal behavior ?

parameterMap: function (options, operation) {
   if (operation !== "read" && options) {
      return kendo.stringify(options);
   }
   return kendo.data.transports["odata-v4"].parameterMap(options, operation);
}
0
Veselin Tsvetanov
Telerik team
answered on 05 Jul 2018, 08:18 AM
Hello Arnaud,

The reason behind the stringifiied numbers are some issues present in the decimal numbers parsing in OData. Therefore, we decided to make the OData service request IEEE754Compatible and represent the numbers as strings.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Data Source
Asked by
Olivier
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Olivier
Top achievements
Rank 1
Share this question
or