Changed JSONNumber to always uses JavaScript-level double->String conversion
  1) more JavaScripty
  2) works around inconsistency in String.valueOf(double) in hosted and web mode.

Review by: bruce


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1965 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/json/client/JSONNumber.java b/user/src/com/google/gwt/json/client/JSONNumber.java
index 5d6ab95..6cb3640 100644
--- a/user/src/com/google/gwt/json/client/JSONNumber.java
+++ b/user/src/com/google/gwt/json/client/JSONNumber.java
@@ -48,7 +48,8 @@
    * Returns the JSON representation of this number.
    */
   @Override
-  public String toString() {
-    return new Double(value).toString();
-  }
+  public native String toString() /*-{
+    // Use JavaScript conversion so that integral values print as integers.
+    return this.@com.google.gwt.json.client.JSONNumber::value + "";
+  }-*/;
 }
diff --git a/user/test/com/google/gwt/json/client/JSONTest.java b/user/test/com/google/gwt/json/client/JSONTest.java
index d946328..3617e27 100644
--- a/user/test/com/google/gwt/json/client/JSONTest.java
+++ b/user/test/com/google/gwt/json/client/JSONTest.java
@@ -347,11 +347,11 @@
   public void testRoundTripEscaping() {
     JSONObject obj = new JSONObject();
     obj.put("a", new JSONNumber(42));
-    obj.put("\\", new JSONNumber(43));
+    obj.put("\\", new JSONNumber(43.5));
     obj.put("\"", new JSONNumber(44));
 
     String toString = obj.toString();
-    assertEquals("{\"a\":42.0, \"\\\\\":43.0, \"\\\"\":44.0}", toString.trim());
+    assertEquals("{\"a\":42, \"\\\\\":43.5, \"\\\"\":44}", toString.trim());
     JSONValue parseResponse = JSONParser.parse(toString);
     JSONObject obj2 = parseResponse.isObject();
     assertJSONObjectEquals(obj, obj2);