Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

Created Feature: json - include decimal point and trailing zero when serializing double round doubles (Azure storage) [119]

$
0
0
I noticed that when serializing a JSON message that contains a double value which is a round number (e.g. 123.0), the value is printed without a decimal point. This poses a problem for our server because it uses the OData protocol, which distinguishes between int and double and does this by looking for the presence of a decimal point in the number.

OData does allow us to explicitly specify the type for each property, but it usually doesn’t need this and can save the extra overhead for numeric types because they can be inferred.

It would greatly benefit us if the Casablanca JSON serializer would ensure doubles get output with a trailing “.0” when they are round numbers. Is this a possibility?

```
double value = 123.0;
web::json::value property_value = web::json::value(value);
std::vector<std::pair<utility::string_t, web::json::value>> fields;
fields.push_back(std::make_pair(U("DoubleProperty"), std::move(property_value)));
fields.reserve(1);
web::json::value input_document = web::json::value::object(fields);
utility::string_t message = input_document.serialize();
web::json::value output_document = web::json::value::parse(message);
bool is_double = output_document.as_object().find(U("DoubleProperty"))->second.is_double();

```

Viewing all articles
Browse latest Browse all 4845

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>