[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: [OASIS Issue Tracker] (ODATA-707) 4.5.3: Type inference for numeric values doesn't work with JSON.parse()
[ https://issues.oasis-open.org/browse/ODATA-707?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=40940#comment-40940 ]
Evan Ireland commented on ODATA-707:
------------------------------------
JSON.parse is always going to return a double regardless of whether odata.type is indicated for a numeric property.
And console.log will likely always omit the fraction if it is zero (12000 is a reasonable rendering of a double with no fraction).
So it isn't clear what advantage comes from this proposed change.
> 4.5.3: Type inference for numeric values doesn't work with JSON.parse()
> -----------------------------------------------------------------------
>
> Key: ODATA-707
> URL: https://issues.oasis-open.org/browse/ODATA-707
> Project: OASIS Open Data Protocol (OData) TC
> Issue Type: Bug
> Components: OData JSON Format
> Affects Versions: V4.0_OS
> Environment: [Proposed][Applied]
> Reporter: Ralf Handl
> Fix For: V4.0_ERRATA01
>
>
> Section 4.5.3 says
> Numeric values have a first-class representation in JSON and do not need any additional annotations. If the value of a property is represented as a number without a dot (.), e or E embedded, the type should be interpreted as an integer value, otherwise as a decimal, double, or single value.
> Unfortunately this type inference does not work for clients using generic JSON parsers, e.g. JSON.parse() in JavaScript. The lines
> var payload = '{ "x" : 1.2e4 }';
> var parsed = JSON.parse(payload);
> console.log(parsed.x);
> will result in 12000.
--
This message was sent by Atlassian JIRA
(v6.2.2#6258)
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]