Chromium Code Reviews| Index: base/json/json_writer.h |
| diff --git a/base/json/json_writer.h b/base/json/json_writer.h |
| index 88c7d58101bf5ca69b5c53a4c233564d828d97ac..9475e3329f75161f470bea5971ca0ec707138e6b 100644 |
| --- a/base/json/json_writer.h |
| +++ b/base/json/json_writer.h |
| @@ -25,7 +25,20 @@ class BASE_EXPORT JSONWriter { |
| // For values of binary type, the value (and key if within a dictionary) |
| // will be omitted from the output. |
| - OPTIONS_OMIT_BINARY_VALUES = 1 << 1 |
| + OPTIONS_OMIT_BINARY_VALUES = 1 << 1, |
| + |
| + // An external consumer of your JSON may expect a 64-bit integer value. |
| + // However, the |Value| classes only support 32-bit ints. One feasible |
| + // way to mitigate this is to use a double to represent the integer. |
| + // However, this class writes all doubles in such a way that causes many |
| + // JSON readers to convert the number to a double instead of a 64-bit int. |
| + // This may break the external consumer of the JSON if it expects a |
| + // 64-bit int. |
| + // This option instructs the writer to write doubles that have no fractional |
| + // part as a normal integer (i.e., without using exponential notation |
| + // or appending a '.0') as long as the value is within the range of a |
| + // 64-bit int. |
| + OPTIONS_ALLOW_DOUBLES_AS_INTEGERS = 1 << 2 |
|
tony
2012/03/06 17:57:25
The name of this is confusing because JSON doesn't
kkania
2012/03/06 21:26:09
That's a much better name, but the option also pre
|
| }; |
| // Given a root node, generates a JSON string and puts it into |json|. |
| @@ -53,7 +66,8 @@ class BASE_EXPORT JSONWriter { |
| // Called recursively to build the JSON string. Whe completed, value is |
| // json_string_ will contain the JSON. |
| void BuildJSONString(const Value* const node, int depth, bool escape, |
| - bool ignore_binary_values); |
| + bool ignore_binary_values, |
| + bool allow_doubles_as_integers); |
| // Appends a quoted, escaped, version of (UTF-8) str to json_string_. |
| void AppendQuotedString(const std::string& str); |