Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3130)

Unified Diff: base/json/json_writer.h

Issue 9016024: Add option for not adding '.0' to the end of doubles that have no fractional (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change name of option Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/json/json_writer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_writer.h
diff --git a/base/json/json_writer.h b/base/json/json_writer.h
index 88c7d58101bf5ca69b5c53a4c233564d828d97ac..665b86a455f65748a46c6f0de784cc2444b6ae73 100644
--- a/base/json/json_writer.h
+++ b/base/json/json_writer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -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 parse the number as a double instead of a 64-bit int.
+ // This may break the external consumer of the JSON if it expects a
+ // 64-bit int.
tony 2012/03/06 21:50:13 I would remove the text from line 30-36. It's suf
kkania 2012/03/06 22:41:57 Done.
+ // 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_OMIT_DOUBLE_TYPE_PRESERVATION = 1 << 2
};
// 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 omit_double_type_preservation);
// Appends a quoted, escaped, version of (UTF-8) str to json_string_.
void AppendQuotedString(const std::string& str);
« no previous file with comments | « no previous file | base/json/json_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698