From b3b540e20e0ac49a1c6ab1c2f45d023c956e6424 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Wed, 19 Feb 2014 00:13:28 +0100 Subject: [PATCH] JSON: Use browser native JSON object for json serialization All modern browsers have native support for JSON serialization [1]. Beside being more performant, this approach seems to fix creating map instead of array problem, so that an array is translated as array "foo": ["bar", "baz"] and not as a map "foo": {"0": "bar", "1": "baz"} That what JsonObject(json).toString() was doing. [1] http://caniuse.com/json Change-Id: I516902273669f58234c5598528f0600ceeab65ec --- .../src/main/java/com/google/gerrit/client/rpc/RestApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/RestApi.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/RestApi.java index 7afded577f..da620d811b 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/RestApi.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/RestApi.java @@ -32,7 +32,6 @@ import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; import com.google.gwt.http.client.URL; import com.google.gwt.json.client.JSONException; -import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONValue; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -373,15 +372,16 @@ public class RestApi { if (!background) { RpcStatus.INSTANCE.onRpcStart(); } - String body = new JSONObject(content).toString(); RequestBuilder req = request(method); req.setHeader("Content-Type", JSON_UTF8); - req.sendRequest(body, httpCallback); + req.sendRequest(str(content), httpCallback); } catch (RequestException e) { httpCallback.onError(null, e); } } + private static native String str(JavaScriptObject jso) /*-{ return JSON.stringify(jso); }-*/; + private void sendRaw(Method method, String body, AsyncCallback cb) { HttpCallback httpCallback = new HttpCallback(background, cb);