summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ArraySerializer.java14
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java4
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/EnumSerializer.java10
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/JsonSerializer.java6
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererVisitor.java5
-rw-r--r--client/build.xml3
-rw-r--r--client/src/com/vaadin/Vaadin.gwt.xml2
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java83
-rw-r--r--client/src/com/vaadin/client/JavaScriptConnectorHelper.java21
-rw-r--r--client/src/com/vaadin/client/Util.java41
-rw-r--r--client/src/com/vaadin/client/VUIDLBrowser.java28
-rw-r--r--client/src/com/vaadin/client/communication/AtmospherePushConnection.java16
-rw-r--r--client/src/com/vaadin/client/communication/Date_Serializer.java13
-rw-r--r--client/src/com/vaadin/client/communication/DiffJSONSerializer.java4
-rw-r--r--client/src/com/vaadin/client/communication/JSONSerializer.java10
-rw-r--r--client/src/com/vaadin/client/communication/JsonDecoder.java113
-rw-r--r--client/src/com/vaadin/client/communication/JsonEncoder.java88
-rw-r--r--client/src/com/vaadin/client/communication/PushConnection.java4
-rw-r--r--client/src/com/vaadin/client/communication/RpcManager.java20
-rw-r--r--client/src/com/vaadin/client/communication/StateChangeEvent.java19
-rw-r--r--client/src/com/vaadin/client/communication/URLReference_Serializer.java18
-rw-r--r--client/src/com/vaadin/client/connectors/AbstractRendererConnector.java5
-rw-r--r--client/src/com/vaadin/client/connectors/ButtonRendererConnector.java5
-rw-r--r--client/src/com/vaadin/client/connectors/ClickableRendererConnector.java9
-rw-r--r--client/src/com/vaadin/client/connectors/GridConnector.java109
-rw-r--r--client/src/com/vaadin/client/connectors/ImageRendererConnector.java11
-rw-r--r--client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java45
-rw-r--r--client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java4
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/MockApplicationConnection.java11
29 files changed, 377 insertions, 344 deletions
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ArraySerializer.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ArraySerializer.java
index 6ffd6c5462..0049ae9b50 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ArraySerializer.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ArraySerializer.java
@@ -19,12 +19,14 @@ package com.vaadin.server.widgetsetutils.metadata;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.typeinfo.JArrayType;
import com.google.gwt.core.ext.typeinfo.JType;
-import com.google.gwt.json.client.JSONArray;
import com.google.gwt.user.rebind.SourceWriter;
import com.vaadin.client.communication.JsonDecoder;
import com.vaadin.client.communication.JsonEncoder;
import com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory;
+import elemental.json.Json;
+import elemental.json.JsonArray;
+
public class ArraySerializer extends JsonSerializer {
private final JArrayType arrayType;
@@ -40,12 +42,12 @@ public class ArraySerializer extends JsonSerializer {
JType leafType = arrayType.getLeafType();
int rank = arrayType.getRank();
- w.println(JSONArray.class.getName() + " jsonArray = " + jsonValue
- + ".isArray();");
+ w.println(JsonArray.class.getName() + " jsonArray = ("
+ + JsonArray.class.getName() + ")" + jsonValue + ";");
// Type value = new Type[jsonArray.size()][][];
w.print(arrayType.getQualifiedSourceName() + " value = new "
- + leafType.getQualifiedSourceName() + "[jsonArray.size()]");
+ + leafType.getQualifiedSourceName() + "[jsonArray.length()]");
for (int i = 1; i < rank; i++) {
w.print("[]");
}
@@ -75,8 +77,8 @@ public class ArraySerializer extends JsonSerializer {
String value, String applicationConnection) {
JType componentType = arrayType.getComponentType();
- w.println(JSONArray.class.getName() + " values = new "
- + JSONArray.class.getName() + "();");
+ w.println(JsonArray.class.getName() + " values = "
+ + Json.class.getName() + ".createArray();");
// JPrimitiveType primitive = componentType.isPrimitive();
w.println("for (int i = 0; i < " + value + ".length; i++) {");
w.indent();
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
index 89421dc3fb..31f59ddee4 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
@@ -37,7 +37,6 @@ import com.google.gwt.core.ext.typeinfo.JParameterizedType;
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.json.client.JSONValue;
import com.google.gwt.thirdparty.guava.common.collect.Sets;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
@@ -48,6 +47,7 @@ import com.vaadin.client.ui.UnknownComponentConnector;
import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.ServerRpc;
import com.vaadin.shared.ui.Connect;
+import elemental.json.JsonValue;
public class ConnectorBundle {
private static final String FAIL_IF_NOT_SERIALIZABLE = "vFailIfNotSerializable";
@@ -105,7 +105,7 @@ public class ConnectorBundle {
.getName());
JType[] deserializeParamTypes = new JType[] {
oracle.findType(com.vaadin.client.metadata.Type.class.getName()),
- oracle.findType(JSONValue.class.getName()),
+ oracle.findType(JsonValue.class.getName()),
oracle.findType(ApplicationConnection.class.getName()) };
String deserializeMethodName = "deserialize";
// Just test that the method exists
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/EnumSerializer.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/EnumSerializer.java
index 18e9652ed1..9876baf946 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/EnumSerializer.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/EnumSerializer.java
@@ -19,9 +19,10 @@ package com.vaadin.server.widgetsetutils.metadata;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.typeinfo.JEnumConstant;
import com.google.gwt.core.ext.typeinfo.JEnumType;
-import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.rebind.SourceWriter;
+import elemental.json.Json;
+
public class EnumSerializer extends JsonSerializer {
private final JEnumType enumType;
@@ -34,8 +35,7 @@ public class EnumSerializer extends JsonSerializer {
@Override
protected void printDeserializerBody(TreeLogger logger, SourceWriter w,
String type, String jsonValue, String connection) {
- w.println("String enumIdentifier = ((" + JSONString.class.getName()
- + ")" + jsonValue + ").stringValue();");
+ w.println("String enumIdentifier = " + jsonValue + ".asString();");
for (JEnumConstant e : enumType.getEnumConstants()) {
w.println("if (\"" + e.getName() + "\".equals(enumIdentifier)) {");
w.indent();
@@ -50,8 +50,8 @@ public class EnumSerializer extends JsonSerializer {
@Override
protected void printSerializerBody(TreeLogger logger, SourceWriter w,
String value, String applicationConnection) {
- // return new JSONString(castedValue.name());
- w.println("return new " + JSONString.class.getName() + "(" + value
+ // return Json.create(castedValue.name());
+ w.println("return " + Json.class.getName() + ".create(" + value
+ ".name());");
}
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/JsonSerializer.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/JsonSerializer.java
index 0509689850..a7a6c568da 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/JsonSerializer.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/JsonSerializer.java
@@ -19,10 +19,10 @@ package com.vaadin.server.widgetsetutils.metadata;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JType;
-import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.rebind.SourceWriter;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.communication.JSONSerializer;
+import elemental.json.JsonValue;
public abstract class JsonSerializer implements GeneratedSerializer {
@@ -51,7 +51,7 @@ public abstract class JsonSerializer implements GeneratedSerializer {
protected void writeSerializerBody(TreeLogger logger, SourceWriter w) {
String qualifiedSourceName = type.getQualifiedSourceName();
- w.println("public " + JSONValue.class.getName() + " serialize("
+ w.println("public " + JsonValue.class.getName() + " serialize("
+ qualifiedSourceName + " value, "
+ ApplicationConnection.class.getName() + " connection) {");
w.indent();
@@ -69,7 +69,7 @@ public abstract class JsonSerializer implements GeneratedSerializer {
// T deserialize(Type type, JSONValue jsonValue, ApplicationConnection
// connection);
w.println("public " + qualifiedSourceName + " deserialize(Type type, "
- + JSONValue.class.getName() + " jsonValue, "
+ + JsonValue.class.getName() + " jsonValue, "
+ ApplicationConnection.class.getName() + " connection) {");
w.indent();
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererVisitor.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererVisitor.java
index 85236efccc..bf1e11c9e3 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererVisitor.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererVisitor.java
@@ -31,9 +31,8 @@ import com.vaadin.client.connectors.AbstractRendererConnector;
* {@link AbstractRendererConnector#getRenderer() getRenderer} method to enable
* automatic creation of an instance of the proper renderer type.
* <li>Stores the presentation type of the connector to enable the
- * {@link AbstractRendererConnector#decode(com.google.gwt.json.client.JSONValue)
- * decode} method to work without having to implement a "getPresentationType"
- * method.
+ * {@link AbstractRendererConnector#decode(elemental.json.JsonValue) decode}
+ * method to work without having to implement a "getPresentationType" method.
* </ul>
*
* @see WidgetInitVisitor
diff --git a/client/build.xml b/client/build.xml
index 19ec05b28a..a6d6f17020 100644
--- a/client/build.xml
+++ b/client/build.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<project name="vaadin-client" basedir="." default="publish-local" xmlns:ivy="antlib:org.apache.ivy.ant">
+<project name="vaadin-client" basedir="." default="publish-local">
<description>
Compiles build helpers used when building other
modules.
@@ -18,6 +18,7 @@
<!-- Could possibly compile GWT files also here to verify that a)
the same dependencies are used and b) all dependencies have been declared -->
<fileset file="${gwt.user.jar}" />
+ <fileset file="${gwt.elemental.jar}" />
</path>
<path id="classpath.test.custom" />
diff --git a/client/src/com/vaadin/Vaadin.gwt.xml b/client/src/com/vaadin/Vaadin.gwt.xml
index 5e8f08fe22..40fbeb5a7a 100644
--- a/client/src/com/vaadin/Vaadin.gwt.xml
+++ b/client/src/com/vaadin/Vaadin.gwt.xml
@@ -10,7 +10,7 @@
<inherits name="com.google.gwt.http.HTTP" />
- <inherits name="com.google.gwt.json.JSON" />
+ <inherits name="elemental.Elemental"/>
<inherits name="com.google.gwt.logging.Logging" />
<set-property name="gwt.logging.enabled" value="TRUE" />
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java
index 7967108a75..741813f2a9 100644
--- a/client/src/com/vaadin/client/ApplicationConnection.java
+++ b/client/src/com/vaadin/client/ApplicationConnection.java
@@ -51,10 +51,6 @@ import com.google.gwt.http.client.RequestCallback;
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.JSONArray;
-import com.google.gwt.json.client.JSONNumber;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONString;
import com.google.gwt.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.Command;
@@ -66,7 +62,6 @@ import com.google.gwt.user.client.Window.ClosingHandler;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConfiguration.ErrorMessage;
-import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadListener;
import com.vaadin.client.communication.HasJavaScriptConnectorHelper;
@@ -101,13 +96,17 @@ import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.JsonConstants;
import com.vaadin.shared.Version;
-import com.vaadin.shared.annotations.NoLayout;
import com.vaadin.shared.communication.LegacyChangeVariablesInvocation;
import com.vaadin.shared.communication.MethodInvocation;
import com.vaadin.shared.communication.SharedState;
import com.vaadin.shared.ui.ui.UIConstants;
import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
+import elemental.json.Json;
+import elemental.json.JsonArray;
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
/**
* This is the client side communication "engine", managing client-server
* communication with its server side counterpart
@@ -767,7 +766,7 @@ public class ApplicationConnection implements HasHandlers {
}
protected void repaintAll() {
- makeUidlRequest(new JSONArray(), getRepaintAllParameters());
+ makeUidlRequest(Json.createArray(), getRepaintAllParameters());
}
/**
@@ -806,21 +805,19 @@ public class ApplicationConnection implements HasHandlers {
* no parameters should be added. Should not start with any
* special character.
*/
- protected void makeUidlRequest(final JSONArray reqInvocations,
+ protected void makeUidlRequest(final JsonArray reqInvocations,
final String extraParams) {
startRequest();
- JSONObject payload = new JSONObject();
+ JsonObject payload = Json.createObject();
if (!getCsrfToken().equals(
ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE)) {
- payload.put(ApplicationConstants.CSRF_TOKEN, new JSONString(
- getCsrfToken()));
+ payload.put(ApplicationConstants.CSRF_TOKEN, getCsrfToken());
}
payload.put(ApplicationConstants.RPC_INVOCATIONS, reqInvocations);
- payload.put(ApplicationConstants.SERVER_SYNC_ID, new JSONNumber(
- lastSeenServerSyncId));
+ payload.put(ApplicationConstants.SERVER_SYNC_ID, lastSeenServerSyncId);
- VConsole.log("Making UIDL Request with params: " + payload);
+ VConsole.log("Making UIDL Request with params: " + payload.toJson());
String uri = translateVaadinUri(ApplicationConstants.APP_PROTOCOL_PREFIX
+ ApplicationConstants.UIDL_PATH + '/');
@@ -843,7 +840,7 @@ public class ApplicationConnection implements HasHandlers {
* @param payload
* The contents of the request to send
*/
- protected void doUidlRequest(final String uri, final JSONObject payload) {
+ protected void doUidlRequest(final String uri, final JsonObject payload) {
doUidlRequest(uri, payload, true);
}
@@ -858,7 +855,7 @@ public class ApplicationConnection implements HasHandlers {
* @param retry
* true when a status code 0 should be retried
*/
- protected void doUidlRequest(final String uri, final JSONObject payload,
+ protected void doUidlRequest(final String uri, final JsonObject payload,
final boolean retry) {
RequestCallback requestCallback = new RequestCallback() {
@Override
@@ -1043,14 +1040,14 @@ public class ApplicationConnection implements HasHandlers {
* @throws RequestException
* if the request could not be sent
*/
- protected void doAjaxRequest(String uri, JSONObject payload,
+ protected void doAjaxRequest(String uri, JsonObject payload,
RequestCallback requestCallback) throws RequestException {
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, uri);
// TODO enable timeout
// rb.setTimeoutMillis(timeoutMillis);
// TODO this should be configurable
rb.setHeader("Content-Type", JsonConstants.JSON_CONTENT_TYPE);
- rb.setRequestData(payload.toString());
+ rb.setRequestData(payload.toJson());
rb.setCallback(requestCallback);
final Request request = rb.send();
@@ -1733,11 +1730,12 @@ public class ApplicationConnection implements HasHandlers {
// Create fake server response that says that the uiConnector
// has no children
- JSONObject fakeHierarchy = new JSONObject();
- fakeHierarchy.put(uiConnectorId, new JSONArray());
- JSONObject fakeJson = new JSONObject();
+ JsonObject fakeHierarchy = Json.createObject();
+ fakeHierarchy.put(uiConnectorId, Json.createArray());
+ JsonObject fakeJson = Json.createObject();
fakeJson.put("hierarchy", fakeHierarchy);
- ValueMap fakeValueMap = fakeJson.getJavaScriptObject().cast();
+ ValueMap fakeValueMap = ((JavaScriptObject) fakeJson.toNative())
+ .cast();
// Update hierarchy based on the fake response
ConnectorHierarchyUpdateResult connectorHierarchyUpdateResult = updateConnectorHierarchy(fakeValueMap);
@@ -2150,14 +2148,14 @@ public class ApplicationConnection implements HasHandlers {
+ Util.getSimpleName(connector));
}
- JSONObject stateJson = new JSONObject(
- states.getJavaScriptObject(connectorId));
+ JavaScriptObject jso = states
+ .getJavaScriptObject(connectorId);
+ JsonObject stateJson = Util.jso2json(jso);
if (connector instanceof HasJavaScriptConnectorHelper) {
((HasJavaScriptConnectorHelper) connector)
.getJavascriptConnectorHelper()
- .setNativeState(
- stateJson.getJavaScriptObject());
+ .setNativeState(jso);
}
SharedState state = connector.getState();
@@ -2166,8 +2164,7 @@ public class ApplicationConnection implements HasHandlers {
if (onlyNoLayoutUpdates) {
Profiler.enter("updateConnectorState @NoLayout handling");
- Set<String> keySet = stateJson.keySet();
- for (String propertyName : keySet) {
+ for (String propertyName : stateJson.keys()) {
Property property = stateType
.getProperty(propertyName);
if (!property.isNoLayout()) {
@@ -2219,7 +2216,7 @@ public class ApplicationConnection implements HasHandlers {
.getConnector(connectorId);
StateChangeEvent event = new StateChangeEvent(connector,
- new JSONObject(), true);
+ Json.createObject(), true);
events.add(event);
@@ -2525,13 +2522,13 @@ public class ApplicationConnection implements HasHandlers {
VConsole.log(" * Performing server to client RPC calls");
- JSONArray rpcCalls = new JSONArray(
- json.getJavaScriptObject("rpc"));
+ JsonArray rpcCalls = Util.jso2json(json
+ .getJavaScriptObject("rpc"));
- int rpcLength = rpcCalls.size();
+ int rpcLength = rpcCalls.length();
for (int i = 0; i < rpcLength; i++) {
try {
- JSONArray rpcCall = (JSONArray) rpcCalls.get(i);
+ JsonArray rpcCall = rpcCalls.getArray(i);
MethodInvocation invocation = rpcManager
.parseAndApplyInvocation(rpcCall,
ApplicationConnection.this);
@@ -2764,21 +2761,18 @@ public class ApplicationConnection implements HasHandlers {
private void buildAndSendVariableBurst(
LinkedHashMap<String, MethodInvocation> pendingInvocations) {
- JSONArray reqJson = new JSONArray();
+ JsonArray reqJson = Json.createArray();
if (!pendingInvocations.isEmpty()) {
if (ApplicationConfiguration.isDebugMode()) {
Util.logVariableBurst(this, pendingInvocations.values());
}
for (MethodInvocation invocation : pendingInvocations.values()) {
- JSONArray invocationJson = new JSONArray();
- invocationJson.set(0,
- new JSONString(invocation.getConnectorId()));
- invocationJson.set(1,
- new JSONString(invocation.getInterfaceName()));
- invocationJson.set(2,
- new JSONString(invocation.getMethodName()));
- JSONArray paramJson = new JSONArray();
+ JsonArray invocationJson = Json.createArray();
+ invocationJson.set(0, invocation.getConnectorId());
+ invocationJson.set(1, invocation.getInterfaceName());
+ invocationJson.set(2, invocation.getMethodName());
+ JsonArray paramJson = Json.createArray();
Type[] parameterTypes = null;
if (!isLegacyVariableChange(invocation)
@@ -2802,10 +2796,11 @@ public class ApplicationConnection implements HasHandlers {
type = parameterTypes[i];
}
Object value = invocation.getParameters()[i];
- paramJson.set(i, JsonEncoder.encode(value, type, this));
+ JsonValue jsonValue = JsonEncoder.encode(value, type, this);
+ paramJson.set(i, jsonValue);
}
invocationJson.set(3, paramJson);
- reqJson.set(reqJson.size(), invocationJson);
+ reqJson.set(reqJson.length(), invocationJson);
}
pendingInvocations.clear();
diff --git a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java
index c4b36d6453..11511f9c36 100644
--- a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java
+++ b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java
@@ -26,7 +26,6 @@ import java.util.Set;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.json.client.JSONArray;
import com.vaadin.client.communication.JavaScriptMethodInvocation;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
@@ -35,6 +34,8 @@ import com.vaadin.client.ui.layout.ElementResizeListener;
import com.vaadin.shared.JavaScriptConnectorState;
import com.vaadin.shared.communication.MethodInvocation;
+import elemental.json.JsonArray;
+
public class JavaScriptConnectorHelper {
private final ServerConnector connector;
@@ -318,7 +319,7 @@ public class JavaScriptConnectorHelper {
iface = findWildcardInterface(method);
}
- JSONArray argumentsArray = new JSONArray(arguments);
+ JsonArray argumentsArray = Util.jso2json(arguments);
Object[] parameters = new Object[arguments.length()];
for (int i = 0; i < parameters.length; i++) {
parameters[i] = argumentsArray.get(i);
@@ -355,7 +356,7 @@ public class JavaScriptConnectorHelper {
MethodInvocation invocation = new JavaScriptMethodInvocation(
connector.getConnectorId(),
"com.vaadin.ui.JavaScript$JavaScriptCallbackRpc", "call",
- new Object[] { name, new JSONArray(arguments) });
+ new Object[] { name, arguments });
connector.getConnection().addMethodInvocationToQueue(invocation, false,
false);
}
@@ -381,8 +382,8 @@ public class JavaScriptConnectorHelper {
}
}-*/;
- public Object[] decodeRpcParameters(JSONArray parametersJson) {
- return new Object[] { parametersJson.getJavaScriptObject() };
+ public Object[] decodeRpcParameters(JsonArray parametersJson) {
+ return new Object[] { Util.json2jso(parametersJson) };
}
public void setTag(int tag) {
@@ -390,18 +391,16 @@ public class JavaScriptConnectorHelper {
}
public void invokeJsRpc(MethodInvocation invocation,
- JSONArray parametersJson) {
+ JsonArray parametersJson) {
String iface = invocation.getInterfaceName();
String method = invocation.getMethodName();
if ("com.vaadin.ui.JavaScript$JavaScriptCallbackRpc".equals(iface)
&& "call".equals(method)) {
- String callbackName = parametersJson.get(0).isString()
- .stringValue();
- JavaScriptObject arguments = parametersJson.get(1).isArray()
- .getJavaScriptObject();
+ String callbackName = parametersJson.getString(0);
+ JavaScriptObject arguments = Util.json2jso(parametersJson.get(1));
invokeCallback(getConnectorWrapper(), callbackName, arguments);
} else {
- JavaScriptObject arguments = parametersJson.getJavaScriptObject();
+ JavaScriptObject arguments = Util.json2jso(parametersJson);
invokeJsRpc(rpcMap, iface, method, arguments);
// Also invoke wildcard interface
invokeJsRpc(rpcMap, "", method, arguments);
diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java
index b78bb8f19e..f0131f0690 100644
--- a/client/src/com/vaadin/client/Util.java
+++ b/client/src/com/vaadin/client/Util.java
@@ -25,6 +25,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.AnchorElement;
@@ -57,6 +59,11 @@ import com.vaadin.shared.communication.MethodInvocation;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.util.SharedUtil;
+import elemental.js.json.JsJsonValue;
+import elemental.js.util.Json;
+import elemental.json.JsonValue;
+import elemental.json.impl.JsonUtil;
+
public class Util {
/**
@@ -1529,6 +1536,40 @@ public class Util {
}-*/;
/**
+ * Converts a native {@link JavaScriptObject} into a {@link JsonValue}. This
+ * is a no-op in GWT code compiled to javascript, but needs some special
+ * handling to work when run in JVM.
+ *
+ * @param jso
+ * the java script object to represent as json
+ * @return the json representation
+ */
+ public static <T extends JsonValue> T jso2json(JavaScriptObject jso) {
+ if (GWT.isProdMode()) {
+ return (T) jso.<JsJsonValue> cast();
+ } else {
+ return JsonUtil.parse(Json.stringify(jso));
+ }
+ }
+
+ /**
+ * Converts a {@link JsonValue} into a native {@link JavaScriptObject}. This
+ * is a no-op in GWT code compiled to javascript, but needs some special
+ * handling to work when run in JVM.
+ *
+ * @param jsonValue
+ * the json value
+ * @return a native javascript object representation of the json value
+ */
+ public static JavaScriptObject json2jso(JsonValue jsonValue) {
+ if (GWT.isProdMode()) {
+ return ((JavaScriptObject) jsonValue.toNative()).cast();
+ } else {
+ return Json.parse(jsonValue.toJson());
+ }
+ }
+
+ /**
* The allowed value inaccuracy when comparing two double-typed pixel
* values.
* <p>
diff --git a/client/src/com/vaadin/client/VUIDLBrowser.java b/client/src/com/vaadin/client/VUIDLBrowser.java
index 4b4fd2f389..08f4c653a5 100644
--- a/client/src/com/vaadin/client/VUIDLBrowser.java
+++ b/client/src/com/vaadin/client/VUIDLBrowser.java
@@ -33,14 +33,16 @@ import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ui.UnknownComponentConnector;
import com.vaadin.client.ui.VWindow;
+import elemental.json.JsonArray;
+import elemental.json.JsonObject;
+import elemental.json.JsonType;
+import elemental.json.JsonValue;
+
/**
* @author Vaadin Ltd
*
@@ -159,7 +161,7 @@ public class VUIDLBrowser extends SimpleTree {
} else {
setText("Unknown connector (" + connectorId + ")");
}
- dir(new JSONObject(stateChanges), this);
+ dir((JsonObject) Util.jso2json(stateChanges), this);
}
@Override
@@ -167,28 +169,28 @@ public class VUIDLBrowser extends SimpleTree {
return connectorId;
}
- private void dir(String key, JSONValue value, SimpleTree tree) {
- if (value.isObject() != null) {
+ private void dir(String key, JsonValue value, SimpleTree tree) {
+ if (value.getType() == JsonType.OBJECT) {
SimpleTree subtree = new SimpleTree(key + "=object");
tree.add(subtree);
- dir(value.isObject(), subtree);
- } else if (value.isArray() != null) {
+ dir((JsonObject) value, subtree);
+ } else if (value.getType() == JsonType.ARRAY) {
SimpleTree subtree = new SimpleTree(key + "=array");
- dir(value.isArray(), subtree);
+ dir((JsonArray) value, subtree);
tree.add(subtree);
} else {
tree.addItem(key + "=" + value);
}
}
- private void dir(JSONObject state, SimpleTree tree) {
- for (String key : state.keySet()) {
+ private void dir(JsonObject state, SimpleTree tree) {
+ for (String key : state.keys()) {
dir(key, state.get(key), tree);
}
}
- private void dir(JSONArray array, SimpleTree tree) {
- for (int i = 0; i < array.size(); ++i) {
+ private void dir(JsonArray array, SimpleTree tree) {
+ for (int i = 0; i < array.length(); ++i) {
dir("" + i, array.get(i), tree);
}
}
diff --git a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java
index 5073e0ce5d..f6f888c98b 100644
--- a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java
+++ b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java
@@ -20,7 +20,6 @@ import java.util.ArrayList;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.Command;
import com.vaadin.client.ApplicationConfiguration;
import com.vaadin.client.ApplicationConnection;
@@ -33,6 +32,7 @@ import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.communication.PushConstants;
import com.vaadin.shared.ui.ui.UIConstants;
import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
+import elemental.json.JsonObject;
/**
* The default {@link PushConnection} implementation that uses Atmosphere for
@@ -111,7 +111,7 @@ public class AtmospherePushConnection implements PushConnection {
private JavaScriptObject socket;
- private ArrayList<JSONObject> messageQueue = new ArrayList<JSONObject>();
+ private ArrayList<JsonObject> messageQueue = new ArrayList<JsonObject>();
private State state = State.CONNECT_PENDING;
@@ -197,25 +197,25 @@ public class AtmospherePushConnection implements PushConnection {
}
@Override
- public void push(JSONObject message) {
+ public void push(JsonObject message) {
switch (state) {
case CONNECT_PENDING:
assert isActive();
- VConsole.log("Queuing push message: " + message);
+ VConsole.log("Queuing push message: " + message.toJson());
messageQueue.add(message);
break;
case CONNECTED:
assert isActive();
- VConsole.log("Sending push message: " + message);
+ VConsole.log("Sending push message: " + message.toJson());
if (transport.equals("websocket")) {
FragmentedMessage fragmented = new FragmentedMessage(
- message.toString());
+ message.toJson());
while (fragmented.hasNextFragment()) {
doPush(socket, fragmented.getNextFragment());
}
} else {
- doPush(socket, message.toString());
+ doPush(socket, message.toJson());
}
break;
case DISCONNECT_PENDING:
@@ -254,7 +254,7 @@ public class AtmospherePushConnection implements PushConnection {
switch (state) {
case CONNECT_PENDING:
state = State.CONNECTED;
- for (JSONObject message : messageQueue) {
+ for (JsonObject message : messageQueue) {
push(message);
}
messageQueue.clear();
diff --git a/client/src/com/vaadin/client/communication/Date_Serializer.java b/client/src/com/vaadin/client/communication/Date_Serializer.java
index 15ef3869aa..14eb6e4e3d 100644
--- a/client/src/com/vaadin/client/communication/Date_Serializer.java
+++ b/client/src/com/vaadin/client/communication/Date_Serializer.java
@@ -17,11 +17,12 @@ package com.vaadin.client.communication;
import java.util.Date;
-import com.google.gwt.json.client.JSONNumber;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.metadata.Type;
+import elemental.json.Json;
+import elemental.json.JsonValue;
+
/**
* Client side serializer/deserializer for java.util.Date
*
@@ -31,14 +32,14 @@ import com.vaadin.client.metadata.Type;
public class Date_Serializer implements JSONSerializer<Date> {
@Override
- public Date deserialize(Type type, JSONValue jsonValue,
+ public Date deserialize(Type type, JsonValue jsonValue,
ApplicationConnection connection) {
- return new Date((long) ((JSONNumber) jsonValue).doubleValue());
+ return new Date((long) jsonValue.asNumber());
}
@Override
- public JSONValue serialize(Date value, ApplicationConnection connection) {
- return new JSONNumber(value.getTime());
+ public JsonValue serialize(Date value, ApplicationConnection connection) {
+ return Json.create(value.getTime());
}
}
diff --git a/client/src/com/vaadin/client/communication/DiffJSONSerializer.java b/client/src/com/vaadin/client/communication/DiffJSONSerializer.java
index 59575604a1..d433a8964c 100644
--- a/client/src/com/vaadin/client/communication/DiffJSONSerializer.java
+++ b/client/src/com/vaadin/client/communication/DiffJSONSerializer.java
@@ -15,9 +15,9 @@
*/
package com.vaadin.client.communication;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.metadata.Type;
+import elemental.json.JsonValue;
public interface DiffJSONSerializer<T> extends JSONSerializer<T> {
/**
@@ -27,6 +27,6 @@ public interface DiffJSONSerializer<T> extends JSONSerializer<T> {
* @param jsonValue
* @param connection
*/
- public void update(T target, Type type, JSONValue jsonValue,
+ public void update(T target, Type type, JsonValue jsonValue,
ApplicationConnection connection);
}
diff --git a/client/src/com/vaadin/client/communication/JSONSerializer.java b/client/src/com/vaadin/client/communication/JSONSerializer.java
index 3327baf842..59e0329ae1 100644
--- a/client/src/com/vaadin/client/communication/JSONSerializer.java
+++ b/client/src/com/vaadin/client/communication/JSONSerializer.java
@@ -16,16 +16,16 @@
package com.vaadin.client.communication;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.metadata.Type;
+import elemental.json.JsonValue;
/**
* Implementors of this interface knows how to serialize an Object of a given
* type to JSON and how to deserialize the JSON back into an object.
* <p>
* The {@link #serialize(Object, ApplicationConnection)} and
- * {@link #deserialize(Type, JSONValue, ApplicationConnection)} methods must be
+ * {@link #deserialize(Type, JsonValue, ApplicationConnection)} methods must be
* symmetric so they can be chained and produce the original result (or an equal
* result).
* <p>
@@ -53,12 +53,12 @@ public interface JSONSerializer<T> {
*
* @return A deserialized object
*/
- T deserialize(Type type, JSONValue jsonValue,
+ T deserialize(Type type, JsonValue jsonValue,
ApplicationConnection connection);
/**
* Serialize the given object into JSON. Must be compatible with
- * {@link #deserialize(Type, JSONValue, ApplicationConnection)} and also
+ * {@link #deserialize(Type, JsonValue, ApplicationConnection)} and also
* with the server side JsonCodec.decodeCustomType method.
*
* @param value
@@ -67,6 +67,6 @@ public interface JSONSerializer<T> {
* the application connection providing the context
* @return A JSON serialized version of the object
*/
- JSONValue serialize(T value, ApplicationConnection connection);
+ JsonValue serialize(T value, ApplicationConnection connection);
}
diff --git a/client/src/com/vaadin/client/communication/JsonDecoder.java b/client/src/com/vaadin/client/communication/JsonDecoder.java
index 37c113bb2f..a8adbac0c6 100644
--- a/client/src/com/vaadin/client/communication/JsonDecoder.java
+++ b/client/src/com/vaadin/client/communication/JsonDecoder.java
@@ -24,10 +24,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.FastStringSet;
@@ -38,15 +34,20 @@ import com.vaadin.client.metadata.Property;
import com.vaadin.client.metadata.Type;
import com.vaadin.shared.Connector;
+import elemental.json.JsonArray;
+import elemental.json.JsonObject;
+import elemental.json.JsonType;
+import elemental.json.JsonValue;
+
/**
* Client side decoder for decodeing shared state and other values from JSON
* received from the server.
- *
+ *
* Currently, basic data types as well as Map, String[] and Object[] are
* supported, where maps and Object[] can contain other supported data types.
- *
+ *
* TODO extensible type support
- *
+ *
* @since 7.0
*/
public class JsonDecoder {
@@ -72,18 +73,18 @@ public class JsonDecoder {
/**
* Decode a JSON array with two elements (type and value) into a client-side
* type, recursively if necessary.
- *
+ *
* @param jsonValue
* JSON value with encoded data
* @param connection
* reference to the current ApplicationConnection
* @return decoded value (does not contain JSON types)
*/
- public static Object decodeValue(Type type, JSONValue jsonValue,
+ public static Object decodeValue(Type type, JsonValue jsonValue,
Object target, ApplicationConnection connection) {
// Null is null, regardless of type
- if (jsonValue.isNull() != null) {
+ if (jsonValue.getType() == JsonType.NULL) {
return null;
}
@@ -93,41 +94,36 @@ public class JsonDecoder {
return decodeMap(type, jsonValue, connection);
} else if (List.class.getName().equals(baseTypeName)
|| ArrayList.class.getName().equals(baseTypeName)) {
- return decodeList(type, (JSONArray) jsonValue, connection);
+ assert jsonValue.getType() == JsonType.ARRAY;
+ return decodeList(type, (JsonArray) jsonValue, connection);
} else if (Set.class.getName().equals(baseTypeName)) {
- return decodeSet(type, (JSONArray) jsonValue, connection);
+ assert jsonValue.getType() == JsonType.ARRAY;
+ return decodeSet(type, (JsonArray) jsonValue, connection);
} else if (String.class.getName().equals(baseTypeName)) {
- return ((JSONString) jsonValue).stringValue();
+ return jsonValue.asString();
} else if (Integer.class.getName().equals(baseTypeName)) {
- return Integer.valueOf(String.valueOf(jsonValue));
+ return Integer.valueOf((int) jsonValue.asNumber());
} else if (Long.class.getName().equals(baseTypeName)) {
- // TODO handle properly
- return Long.valueOf(String.valueOf(jsonValue));
+ return Long.valueOf((long) jsonValue.asNumber());
} else if (Float.class.getName().equals(baseTypeName)) {
- // TODO handle properly
- return Float.valueOf(String.valueOf(jsonValue));
+ return Float.valueOf((float) jsonValue.asNumber());
} else if (Double.class.getName().equals(baseTypeName)) {
- // TODO handle properly
- return Double.valueOf(String.valueOf(jsonValue));
+ return Double.valueOf(jsonValue.asNumber());
} else if (Boolean.class.getName().equals(baseTypeName)) {
- // TODO handle properly
- return Boolean.valueOf(String.valueOf(jsonValue));
+ return Boolean.valueOf(jsonValue.asString());
} else if (Byte.class.getName().equals(baseTypeName)) {
- // TODO handle properly
- return Byte.valueOf(String.valueOf(jsonValue));
+ return Byte.valueOf((byte) jsonValue.asNumber());
} else if (Character.class.getName().equals(baseTypeName)) {
- // TODO handle properly
- return Character.valueOf(((JSONString) jsonValue).stringValue()
- .charAt(0));
+ return Character.valueOf(jsonValue.asString().charAt(0));
} else if (Connector.class.getName().equals(baseTypeName)) {
return ConnectorMap.get(connection).getConnector(
- ((JSONString) jsonValue).stringValue());
+ jsonValue.asString());
} else {
return decodeObject(type, jsonValue, target, connection);
}
}
- private static Object decodeObject(Type type, JSONValue jsonValue,
+ private static Object decodeObject(Type type, JsonValue jsonValue,
Object target, ApplicationConnection connection) {
Profiler.enter("JsonDecoder.decodeObject");
JSONSerializer<Object> serializer = (JSONSerializer<Object>) type
@@ -152,14 +148,12 @@ public class JsonDecoder {
if (target == null) {
target = type.createInstance();
}
- JSONObject jsonObject = jsonValue.isObject();
+ JsonObject jsonObject = (JsonObject) jsonValue;
int size = properties.size();
for (int i = 0; i < size; i++) {
Property property = properties.get(i);
- JSONValue encodedPropertyValue = jsonObject.get(property
- .getName());
- if (encodedPropertyValue == null) {
+ if (!jsonObject.hasKey(property.getName())) {
continue;
}
@@ -173,6 +167,8 @@ public class JsonDecoder {
}
Profiler.leave("JsonDecoder.decodeObject meta data processing");
+ JsonValue encodedPropertyValue = jsonObject.get(property
+ .getName());
Object decodedValue = decodeValue(propertyType,
encodedPropertyValue, propertyReference, connection);
Profiler.enter("JsonDecoder.decodeObject meta data processing");
@@ -194,13 +190,13 @@ public class JsonDecoder {
return !decodedWithoutReference.contains(type.getBaseTypeName());
}
- private static Map<Object, Object> decodeMap(Type type, JSONValue jsonMap,
+ private static Map<Object, Object> decodeMap(Type type, JsonValue jsonMap,
ApplicationConnection connection) {
// Client -> server encodes empty map as an empty array because of
// #8906. Do the same for server -> client to maintain symmetry.
- if (jsonMap instanceof JSONArray) {
- JSONArray array = (JSONArray) jsonMap;
- if (array.size() == 0) {
+ if (jsonMap.getType() == JsonType.ARRAY) {
+ JsonArray array = (JsonArray) jsonMap;
+ if (array.length() == 0) {
return new HashMap<Object, Object>();
}
}
@@ -209,26 +205,30 @@ public class JsonDecoder {
Type valueType = type.getParameterTypes()[1];
if (keyType.getBaseTypeName().equals(String.class.getName())) {
- return decodeStringMap(valueType, jsonMap, connection);
+ assert jsonMap.getType() == JsonType.OBJECT;
+ return decodeStringMap(valueType, (JsonObject) jsonMap, connection);
} else if (keyType.getBaseTypeName().equals(Connector.class.getName())) {
- return decodeConnectorMap(valueType, jsonMap, connection);
+ assert jsonMap.getType() == JsonType.OBJECT;
+ return decodeConnectorMap(valueType, (JsonObject) jsonMap,
+ connection);
} else {
- return decodeObjectMap(keyType, valueType, jsonMap, connection);
+ assert jsonMap.getType() == JsonType.ARRAY;
+ return decodeObjectMap(keyType, valueType, (JsonArray) jsonMap,
+ connection);
}
}
private static Map<Object, Object> decodeObjectMap(Type keyType,
- Type valueType, JSONValue jsonValue,
+ Type valueType, JsonArray jsonValue,
ApplicationConnection connection) {
Map<Object, Object> map = new HashMap<Object, Object>();
- JSONArray mapArray = (JSONArray) jsonValue;
- JSONArray keys = (JSONArray) mapArray.get(0);
- JSONArray values = (JSONArray) mapArray.get(1);
+ JsonArray keys = jsonValue.get(0);
+ JsonArray values = jsonValue.get(1);
- assert (keys.size() == values.size());
+ assert (keys.length() == values.length());
- for (int i = 0; i < keys.size(); i++) {
+ for (int i = 0; i < keys.length(); i++) {
Object decodedKey = decodeValue(keyType, keys.get(i), null,
connection);
Object decodedValue = decodeValue(valueType, values.get(i), null,
@@ -241,13 +241,12 @@ public class JsonDecoder {
}
private static Map<Object, Object> decodeConnectorMap(Type valueType,
- JSONValue jsonValue, ApplicationConnection connection) {
+ JsonObject jsonMap, ApplicationConnection connection) {
Map<Object, Object> map = new HashMap<Object, Object>();
- JSONObject jsonMap = (JSONObject) jsonValue;
ConnectorMap connectorMap = ConnectorMap.get(connection);
- for (String connectorId : jsonMap.keySet()) {
+ for (String connectorId : jsonMap.keys()) {
Object value = decodeValue(valueType, jsonMap.get(connectorId),
null, connection);
map.put(connectorMap.getConnector(connectorId), value);
@@ -257,12 +256,10 @@ public class JsonDecoder {
}
private static Map<Object, Object> decodeStringMap(Type valueType,
- JSONValue jsonValue, ApplicationConnection connection) {
+ JsonObject jsonMap, ApplicationConnection connection) {
Map<Object, Object> map = new HashMap<Object, Object>();
- JSONObject jsonMap = (JSONObject) jsonValue;
-
- for (String key : jsonMap.keySet()) {
+ for (String key : jsonMap.keys()) {
Object value = decodeValue(valueType, jsonMap.get(key), null,
connection);
map.put(key, value);
@@ -271,7 +268,7 @@ public class JsonDecoder {
return map;
}
- private static List<Object> decodeList(Type type, JSONArray jsonArray,
+ private static List<Object> decodeList(Type type, JsonArray jsonArray,
ApplicationConnection connection) {
List<Object> tokens = new ArrayList<Object>();
decodeIntoCollection(type.getParameterTypes()[0], jsonArray,
@@ -279,7 +276,7 @@ public class JsonDecoder {
return tokens;
}
- private static Set<Object> decodeSet(Type type, JSONArray jsonArray,
+ private static Set<Object> decodeSet(Type type, JsonArray jsonArray,
ApplicationConnection connection) {
Set<Object> tokens = new HashSet<Object>();
decodeIntoCollection(type.getParameterTypes()[0], jsonArray,
@@ -288,11 +285,11 @@ public class JsonDecoder {
}
private static void decodeIntoCollection(Type childType,
- JSONArray jsonArray, ApplicationConnection connection,
+ JsonArray jsonArray, ApplicationConnection connection,
Collection<Object> tokens) {
- for (int i = 0; i < jsonArray.size(); ++i) {
+ for (int i = 0; i < jsonArray.length(); ++i) {
// each entry always has two elements: type and value
- JSONValue entryValue = jsonArray.get(i);
+ JsonValue entryValue = jsonArray.get(i);
tokens.add(decodeValue(childType, entryValue, null, connection));
}
}
diff --git a/client/src/com/vaadin/client/communication/JsonEncoder.java b/client/src/com/vaadin/client/communication/JsonEncoder.java
index 6783e802ec..fad4ad602a 100644
--- a/client/src/com/vaadin/client/communication/JsonEncoder.java
+++ b/client/src/com/vaadin/client/communication/JsonEncoder.java
@@ -22,13 +22,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONBoolean;
-import com.google.gwt.json.client.JSONNull;
-import com.google.gwt.json.client.JSONNumber;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.JsArrayObject;
import com.vaadin.client.metadata.NoDataException;
@@ -38,6 +31,11 @@ import com.vaadin.shared.Connector;
import com.vaadin.shared.JsonConstants;
import com.vaadin.shared.communication.UidlValue;
+import elemental.json.Json;
+import elemental.json.JsonArray;
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
/**
* Encoder for converting RPC parameters and other values to JSON for transfer
* between the client and the server.
@@ -60,27 +58,27 @@ public class JsonEncoder {
* @param connection
* @return JSON representation of the value
*/
- public static JSONValue encode(Object value, Type type,
+ public static JsonValue encode(Object value, Type type,
ApplicationConnection connection) {
if (null == value) {
- return JSONNull.getInstance();
- } else if (value instanceof JSONValue) {
- return (JSONValue) value;
+ return Json.createNull();
+ } else if (value instanceof JsonValue) {
+ return (JsonValue) value;
} else if (value instanceof String[]) {
String[] array = (String[]) value;
- JSONArray jsonArray = new JSONArray();
+ JsonArray jsonArray = Json.createArray();
for (int i = 0; i < array.length; ++i) {
- jsonArray.set(i, new JSONString(array[i]));
+ jsonArray.set(i, array[i]);
}
return jsonArray;
} else if (value instanceof String) {
- return new JSONString((String) value);
+ return Json.create((String) value);
} else if (value instanceof Boolean) {
- return JSONBoolean.getInstance((Boolean) value);
+ return Json.create((Boolean) value);
} else if (value instanceof Byte) {
- return new JSONNumber((Byte) value);
+ return Json.create((Byte) value);
} else if (value instanceof Character) {
- return new JSONString(String.valueOf(value));
+ return Json.create(String.valueOf(value));
} else if (value instanceof Object[] && type == null) {
// Non-legacy arrays handed by generated serializer
return encodeLegacyObjectArray((Object[]) value, connection);
@@ -90,7 +88,7 @@ public class JsonEncoder {
return encodeMap((Map) value, type, connection);
} else if (value instanceof Connector) {
Connector connector = (Connector) value;
- return new JSONString(connector.getConnectorId());
+ return Json.create(connector.getConnectorId());
} else if (value instanceof Collection) {
return encodeCollection((Collection) value, type, connection);
} else if (value instanceof UidlValue) {
@@ -108,21 +106,21 @@ public class JsonEncoder {
String transportType = getTransportType(value);
if (transportType != null) {
// Send the string value for remaining legacy types
- return new JSONString(String.valueOf(value));
+ return Json.create(String.valueOf(value));
} else if (type != null) {
// And finally try using bean serialization logic
try {
JsArrayObject<Property> properties = type
.getPropertiesAsArray();
- JSONObject jsonObject = new JSONObject();
+ JsonObject jsonObject = Json.createObject();
int size = properties.size();
for (int i = 0; i < size; i++) {
Property property = properties.get(i);
Object propertyValue = property.getValue(value);
Type propertyType = property.getType();
- JSONValue encodedPropertyValue = encode(propertyValue,
+ JsonValue encodedPropertyValue = encode(propertyValue,
propertyType, connection);
jsonObject
.put(property.getName(), encodedPropertyValue);
@@ -141,11 +139,11 @@ public class JsonEncoder {
}
}
- private static JSONValue encodeVariableChange(UidlValue uidlValue,
+ private static JsonValue encodeVariableChange(UidlValue uidlValue,
ApplicationConnection connection) {
Object value = uidlValue.getValue();
- JSONArray jsonArray = new JSONArray();
+ JsonArray jsonArray = Json.createArray();
String transportType = getTransportType(value);
if (transportType == null) {
/*
@@ -159,13 +157,13 @@ public class JsonEncoder {
throw new IllegalArgumentException("Cannot encode object of type "
+ valueType);
}
- jsonArray.set(0, new JSONString(transportType));
+ jsonArray.set(0, Json.create(transportType));
jsonArray.set(1, encode(value, null, connection));
return jsonArray;
}
- private static JSONValue encodeMap(Map<Object, Object> map, Type type,
+ private static JsonValue encodeMap(Map<Object, Object> map, Type type,
ApplicationConnection connection) {
/*
* As we have no info about declared types, we instead select encoding
@@ -174,7 +172,7 @@ public class JsonEncoder {
* server-side decoding must check for. (see #8906)
*/
if (map.isEmpty()) {
- return new JSONArray();
+ return Json.createArray();
}
Object firstKey = map.keySet().iterator().next();
@@ -190,7 +188,7 @@ public class JsonEncoder {
}
}
- private static JSONValue encodeChildValue(Object value,
+ private static JsonValue encodeChildValue(Object value,
Type collectionType, int typeIndex, ApplicationConnection connection) {
if (collectionType == null) {
return encode(new UidlValue(value), null, connection);
@@ -204,35 +202,35 @@ public class JsonEncoder {
}
}
- private static JSONValue encodeObjectMap(Map<Object, Object> map,
+ private static JsonArray encodeObjectMap(Map<Object, Object> map,
Type type, ApplicationConnection connection) {
- JSONArray keys = new JSONArray();
- JSONArray values = new JSONArray();
+ JsonArray keys = Json.createArray();
+ JsonArray values = Json.createArray();
assert type != null : "Should only be used for non-legacy types";
for (Entry<?, ?> entry : map.entrySet()) {
- keys.set(keys.size(),
+ keys.set(keys.length(),
encodeChildValue(entry.getKey(), type, 0, connection));
- values.set(values.size(),
+ values.set(values.length(),
encodeChildValue(entry.getValue(), type, 1, connection));
}
- JSONArray keysAndValues = new JSONArray();
+ JsonArray keysAndValues = Json.createArray();
keysAndValues.set(0, keys);
keysAndValues.set(1, values);
return keysAndValues;
}
- private static JSONValue encodeConnectorMap(Map<Object, Object> map,
+ private static JsonValue encodeConnectorMap(Map<Object, Object> map,
Type type, ApplicationConnection connection) {
- JSONObject jsonMap = new JSONObject();
+ JsonObject jsonMap = Json.createObject();
for (Entry<?, ?> entry : map.entrySet()) {
Connector connector = (Connector) entry.getKey();
- JSONValue encodedValue = encodeChildValue(entry.getValue(), type,
+ JsonValue encodedValue = encodeChildValue(entry.getValue(), type,
1, connection);
jsonMap.put(connector.getConnectorId(), encodedValue);
@@ -241,9 +239,9 @@ public class JsonEncoder {
return jsonMap;
}
- private static JSONValue encodeStringMap(Map<Object, Object> map,
+ private static JsonValue encodeStringMap(Map<Object, Object> map,
Type type, ApplicationConnection connection) {
- JSONObject jsonMap = new JSONObject();
+ JsonObject jsonMap = Json.createObject();
for (Entry<?, ?> entry : map.entrySet()) {
String key = (String) entry.getKey();
@@ -255,14 +253,14 @@ public class JsonEncoder {
return jsonMap;
}
- private static JSONValue encodeEnum(Enum<?> e,
+ private static JsonValue encodeEnum(Enum<?> e,
ApplicationConnection connection) {
- return new JSONString(e.toString());
+ return Json.create(e.toString());
}
- private static JSONValue encodeLegacyObjectArray(Object[] array,
+ private static JsonValue encodeLegacyObjectArray(Object[] array,
ApplicationConnection connection) {
- JSONArray jsonArray = new JSONArray();
+ JsonArray jsonArray = Json.createArray();
for (int i = 0; i < array.length; ++i) {
// TODO handle object graph loops?
Object value = array[i];
@@ -271,12 +269,12 @@ public class JsonEncoder {
return jsonArray;
}
- private static JSONValue encodeCollection(Collection collection, Type type,
+ private static JsonArray encodeCollection(Collection collection, Type type,
ApplicationConnection connection) {
- JSONArray jsonArray = new JSONArray();
+ JsonArray jsonArray = Json.createArray();
int idx = 0;
for (Object o : collection) {
- JSONValue encodedObject = encodeChildValue(o, type, 0, connection);
+ JsonValue encodedObject = encodeChildValue(o, type, 0, connection);
jsonArray.set(idx++, encodedObject);
}
if (collection instanceof Set) {
diff --git a/client/src/com/vaadin/client/communication/PushConnection.java b/client/src/com/vaadin/client/communication/PushConnection.java
index 3bdb18ff1b..8066746dc6 100644
--- a/client/src/com/vaadin/client/communication/PushConnection.java
+++ b/client/src/com/vaadin/client/communication/PushConnection.java
@@ -16,11 +16,11 @@
package com.vaadin.client.communication;
-import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.Command;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ApplicationConnection.CommunicationErrorHandler;
import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
+import elemental.json.JsonObject;
/**
* Represents the client-side endpoint of a bidirectional ("push") communication
@@ -61,7 +61,7 @@ public interface PushConnection {
*
* @see #isActive()
*/
- public void push(JSONObject payload);
+ public void push(JsonObject payload);
/**
* Checks whether this push connection is in a state where it can push
diff --git a/client/src/com/vaadin/client/communication/RpcManager.java b/client/src/com/vaadin/client/communication/RpcManager.java
index efedfe12a9..753db4a19b 100644
--- a/client/src/com/vaadin/client/communication/RpcManager.java
+++ b/client/src/com/vaadin/client/communication/RpcManager.java
@@ -18,8 +18,6 @@ package com.vaadin.client.communication;
import java.util.Collection;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONString;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.ServerConnector;
@@ -30,6 +28,8 @@ import com.vaadin.client.metadata.Type;
import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.MethodInvocation;
+import elemental.json.JsonArray;
+
/**
* Client side RPC manager that can invoke methods based on RPC calls received
* from the server.
@@ -97,14 +97,14 @@ public class RpcManager {
}
}
- public MethodInvocation parseAndApplyInvocation(JSONArray rpcCall,
+ public MethodInvocation parseAndApplyInvocation(JsonArray rpcCall,
ApplicationConnection connection) {
ConnectorMap connectorMap = ConnectorMap.get(connection);
- String connectorId = ((JSONString) rpcCall.get(0)).stringValue();
- String interfaceName = ((JSONString) rpcCall.get(1)).stringValue();
- String methodName = ((JSONString) rpcCall.get(2)).stringValue();
- JSONArray parametersJson = (JSONArray) rpcCall.get(3);
+ String connectorId = rpcCall.getString(0);
+ String interfaceName = rpcCall.getString(1);
+ String methodName = rpcCall.getString(2);
+ JsonArray parametersJson = rpcCall.getArray(3);
ServerConnector connector = connectorMap.getConnector(connectorId);
@@ -130,11 +130,11 @@ public class RpcManager {
}
private void parseMethodParameters(MethodInvocation methodInvocation,
- JSONArray parametersJson, ApplicationConnection connection) {
+ JsonArray parametersJson, ApplicationConnection connection) {
Type[] parameterTypes = getParameterTypes(methodInvocation);
- Object[] parameters = new Object[parametersJson.size()];
- for (int j = 0; j < parametersJson.size(); ++j) {
+ Object[] parameters = new Object[parametersJson.length()];
+ for (int j = 0; j < parametersJson.length(); ++j) {
parameters[j] = JsonDecoder.decodeValue(parameterTypes[j],
parametersJson.get(j), null, connection);
}
diff --git a/client/src/com/vaadin/client/communication/StateChangeEvent.java b/client/src/com/vaadin/client/communication/StateChangeEvent.java
index 6bda41cef2..7db1d1b249 100644
--- a/client/src/com/vaadin/client/communication/StateChangeEvent.java
+++ b/client/src/com/vaadin/client/communication/StateChangeEvent.java
@@ -21,15 +21,16 @@ import java.util.Set;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.json.client.JSONObject;
import com.vaadin.client.FastStringSet;
import com.vaadin.client.JsArrayObject;
import com.vaadin.client.Profiler;
import com.vaadin.client.ServerConnector;
+import com.vaadin.client.Util;
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
import com.vaadin.client.metadata.NoDataException;
import com.vaadin.client.metadata.Property;
import com.vaadin.client.ui.AbstractConnector;
+import elemental.json.JsonObject;
public class StateChangeEvent extends
AbstractServerConnectorEvent<StateChangeHandler> {
@@ -54,7 +55,7 @@ public class StateChangeEvent extends
private boolean initialStateChange = false;
- private JSONObject stateJson;
+ private JsonObject stateJson;
@Override
public Type<StateChangeHandler> getAssociatedType() {
@@ -69,7 +70,7 @@ public class StateChangeEvent extends
* @param changedPropertiesSet
* a set of names of the changed properties
* @deprecated As of 7.0.1, use
- * {@link #StateChangeEvent(ServerConnector, JSONObject, boolean)}
+ * {@link #StateChangeEvent(ServerConnector, JsonObject, boolean)}
* instead for improved performance.
*/
@Deprecated
@@ -93,7 +94,7 @@ public class StateChangeEvent extends
* @param changedProperties
* a set of names of the changed properties
* @deprecated As of 7.0.2, use
- * {@link #StateChangeEvent(ServerConnector, JSONObject, boolean)}
+ * {@link #StateChangeEvent(ServerConnector, JsonObject, boolean)}
* instead for improved performance.
*/
@Deprecated
@@ -114,7 +115,7 @@ public class StateChangeEvent extends
* <code>true</code> if the state change is for a new connector,
* otherwise <code>false</code>
*/
- public StateChangeEvent(ServerConnector connector, JSONObject stateJson,
+ public StateChangeEvent(ServerConnector connector, JsonObject stateJson,
boolean initialStateChange) {
setConnector(connector);
this.stateJson = stateJson;
@@ -203,7 +204,7 @@ public class StateChangeEvent extends
return true;
} else if (stateJson != null) {
// Check whether it's in the json object
- return isInJson(property, stateJson.getJavaScriptObject());
+ return isInJson(property, Util.json2jso(stateJson));
} else {
// Legacy cases
if (changedProperties != null) {
@@ -297,13 +298,13 @@ public class StateChangeEvent extends
* the base name of the current object
*/
@Deprecated
- private static void addJsonFields(JSONObject json,
+ private static void addJsonFields(JsonObject json,
FastStringSet changedProperties, String context) {
- for (String key : json.keySet()) {
+ for (String key : json.keys()) {
String fieldName = context + key;
changedProperties.add(fieldName);
- JSONObject object = json.get(key).isObject();
+ JsonObject object = json.get(key);
if (object != null) {
addJsonFields(object, changedProperties, fieldName + ".");
}
diff --git a/client/src/com/vaadin/client/communication/URLReference_Serializer.java b/client/src/com/vaadin/client/communication/URLReference_Serializer.java
index 4ecdc606d2..71403c3fb3 100644
--- a/client/src/com/vaadin/client/communication/URLReference_Serializer.java
+++ b/client/src/com/vaadin/client/communication/URLReference_Serializer.java
@@ -16,26 +16,28 @@
package com.vaadin.client.communication;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.metadata.Type;
import com.vaadin.shared.communication.URLReference;
+import elemental.json.Json;
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
public class URLReference_Serializer implements JSONSerializer<URLReference> {
// setURL() -> uRL as first char becomes lower case...
private static final String URL_FIELD = "uRL";
@Override
- public URLReference deserialize(Type type, JSONValue jsonValue,
+ public URLReference deserialize(Type type, JsonValue jsonValue,
ApplicationConnection connection) {
TranslatedURLReference reference = GWT
.create(TranslatedURLReference.class);
reference.setConnection(connection);
- JSONObject json = (JSONObject) jsonValue;
- if (json.containsKey(URL_FIELD)) {
- JSONValue jsonURL = json.get(URL_FIELD);
+ JsonObject json = (JsonObject) jsonValue;
+ if (json.hasKey(URL_FIELD)) {
+ JsonValue jsonURL = json.get(URL_FIELD);
String URL = (String) JsonDecoder.decodeValue(
new Type(String.class.getName(), null), jsonURL, null,
connection);
@@ -45,9 +47,9 @@ public class URLReference_Serializer implements JSONSerializer<URLReference> {
}
@Override
- public JSONValue serialize(URLReference value,
+ public JsonValue serialize(URLReference value,
ApplicationConnection connection) {
- JSONObject json = new JSONObject();
+ JsonObject json = Json.createObject();
// No type info required for encoding a String...
json.put(URL_FIELD,
JsonEncoder.encode(value.getURL(), null, connection));
diff --git a/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java b/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java
index ef117ad828..781de78d06 100644
--- a/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java
+++ b/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java
@@ -15,7 +15,6 @@
*/
package com.vaadin.client.connectors;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.Util;
import com.vaadin.client.communication.JsonDecoder;
@@ -26,6 +25,8 @@ import com.vaadin.client.metadata.TypeData;
import com.vaadin.client.metadata.TypeDataStore;
import com.vaadin.client.renderers.Renderer;
+import elemental.json.JsonValue;
+
/**
* An abstract base class for renderer connectors. A renderer connector is used
* to link a client-side {@link Renderer} to a server-side
@@ -122,7 +123,7 @@ public abstract class AbstractRendererConnector<T> extends
* the value to decode
* @return the decoded value of {@code value}
*/
- public T decode(JSONValue value) {
+ public T decode(JsonValue value) {
@SuppressWarnings("unchecked")
T decodedValue = (T) JsonDecoder.decodeValue(presentationType, value,
null, getConnection());
diff --git a/client/src/com/vaadin/client/connectors/ButtonRendererConnector.java b/client/src/com/vaadin/client/connectors/ButtonRendererConnector.java
index 4d09c20db2..a74db590da 100644
--- a/client/src/com/vaadin/client/connectors/ButtonRendererConnector.java
+++ b/client/src/com/vaadin/client/connectors/ButtonRendererConnector.java
@@ -15,12 +15,13 @@
*/
package com.vaadin.client.connectors;
-import com.google.gwt.json.client.JSONObject;
import com.google.web.bindery.event.shared.HandlerRegistration;
import com.vaadin.client.renderers.ButtonRenderer;
import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
import com.vaadin.shared.ui.Connect;
+import elemental.json.JsonObject;
+
/**
* A connector for {@link ButtonRenderer}.
*
@@ -37,7 +38,7 @@ public class ButtonRendererConnector extends ClickableRendererConnector<String>
@Override
protected HandlerRegistration addClickHandler(
- RendererClickHandler<JSONObject> handler) {
+ RendererClickHandler<JsonObject> handler) {
return getRenderer().addClickHandler(handler);
}
}
diff --git a/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java b/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java
index f450e6ad62..ee995384f3 100644
--- a/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java
+++ b/client/src/com/vaadin/client/connectors/ClickableRendererConnector.java
@@ -15,13 +15,14 @@
*/
package com.vaadin.client.connectors;
-import com.google.gwt.json.client.JSONObject;
import com.google.web.bindery.event.shared.HandlerRegistration;
import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.renderers.ClickableRenderer.RendererClickEvent;
import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
import com.vaadin.shared.ui.grid.renderers.RendererClickRpc;
+import elemental.json.JsonObject;
+
/**
* An abstract base class for {@link ClickableRenderer} connectors.
*
@@ -38,9 +39,9 @@ public abstract class ClickableRendererConnector<T> extends
@Override
protected void init() {
- clickRegistration = addClickHandler(new RendererClickHandler<JSONObject>() {
+ clickRegistration = addClickHandler(new RendererClickHandler<JsonObject>() {
@Override
- public void onClick(RendererClickEvent<JSONObject> event) {
+ public void onClick(RendererClickEvent<JsonObject> event) {
getRpcProxy(RendererClickRpc.class).click(
event.getCell().getRow(),
event.getCell().getColumn(),
@@ -56,5 +57,5 @@ public abstract class ClickableRendererConnector<T> extends
}
protected abstract HandlerRegistration addClickHandler(
- RendererClickHandler<JSONObject> handler);
+ RendererClickHandler<JsonObject> handler);
}
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java
index 5d6e0c7f2c..b5e5adba8b 100644
--- a/client/src/com/vaadin/client/connectors/GridConnector.java
+++ b/client/src/com/vaadin/client/connectors/GridConnector.java
@@ -29,8 +29,6 @@ import java.util.logging.Logger;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
@@ -65,10 +63,10 @@ import com.vaadin.client.widgets.Grid.HeaderCell;
import com.vaadin.client.widgets.Grid.HeaderRow;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.Connect;
-import com.vaadin.shared.ui.grid.GridClientRpc;
-import com.vaadin.shared.ui.grid.GridColumnState;
import com.vaadin.shared.ui.grid.EditorClientRpc;
import com.vaadin.shared.ui.grid.EditorServerRpc;
+import com.vaadin.shared.ui.grid.GridClientRpc;
+import com.vaadin.shared.ui.grid.GridColumnState;
import com.vaadin.shared.ui.grid.GridServerRpc;
import com.vaadin.shared.ui.grid.GridState;
import com.vaadin.shared.ui.grid.GridState.SharedSelectionMode;
@@ -77,6 +75,9 @@ import com.vaadin.shared.ui.grid.GridStaticSectionState.CellState;
import com.vaadin.shared.ui.grid.GridStaticSectionState.RowState;
import com.vaadin.shared.ui.grid.ScrollDestination;
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
/**
* Connects the client side {@link Grid} widget with the server side
* {@link com.vaadin.ui.components.grid.Grid} component.
@@ -93,23 +94,22 @@ public class GridConnector extends AbstractHasComponentsConnector implements
SimpleManagedLayout {
private static final class CustomCellStyleGenerator implements
- CellStyleGenerator<JSONObject> {
+ CellStyleGenerator<JsonObject> {
@Override
- public String getStyle(CellReference<JSONObject> cellReference) {
- JSONValue cellstyles = cellReference.getRow().get(
- GridState.JSONKEY_CELLSTYLES);
- if (cellstyles == null) {
+ public String getStyle(CellReference<JsonObject> cellReference) {
+ JsonObject row = cellReference.getRow();
+ if (!row.hasKey(GridState.JSONKEY_CELLSTYLES)) {
return null;
}
CustomGridColumn c = (CustomGridColumn) cellReference.getColumn();
- JSONObject cellStylesObject = cellstyles.isObject();
+ JsonObject cellStylesObject = row
+ .getObject(GridState.JSONKEY_CELLSTYLES);
assert cellStylesObject != null;
- JSONValue styleValue = cellStylesObject.get(c.id);
- if (styleValue != null) {
- return styleValue.isString().stringValue();
+ if (cellStylesObject.hasKey(c.id)) {
+ return cellStylesObject.getString(c.id);
} else {
return null;
}
@@ -118,13 +118,12 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
private static final class CustomRowStyleGenerator implements
- RowStyleGenerator<JSONObject> {
+ RowStyleGenerator<JsonObject> {
@Override
- public String getStyle(RowReference<JSONObject> rowReference) {
- JSONValue styleValue = rowReference.getRow().get(
- GridState.JSONKEY_ROWSTYLE);
- if (styleValue != null) {
- return styleValue.isString().stringValue();
+ public String getStyle(RowReference<JsonObject> rowReference) {
+ JsonObject row = rowReference.getRow();
+ if (row.hasKey(GridState.JSONKEY_ROWSTYLE)) {
+ return row.getString(GridState.JSONKEY_ROWSTYLE);
} else {
return null;
}
@@ -136,7 +135,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
* Custom implementation of the custom grid column using a JSONObject to
* represent the cell value and String as a column type.
*/
- private class CustomGridColumn extends Grid.Column<Object, JSONObject> {
+ private class CustomGridColumn extends Grid.Column<Object, JsonObject> {
private final String id;
@@ -152,20 +151,14 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
@Override
- public Object getValue(final JSONObject obj) {
- final JSONValue rowData = obj.get(GridState.JSONKEY_DATA);
- final JSONObject rowDataObject = rowData.isObject();
- assert rowDataObject != null : "Was unable to parse JSON into an array: "
- + rowData;
+ public Object getValue(final JsonObject obj) {
+ final JsonObject rowData = obj.getObject(GridState.JSONKEY_DATA);
- final JSONValue columnValue = rowDataObject.get(id);
-
- /*
- * note, Java "null" is different from JSONValue "null" (i.e.
- * JSONNull).
- */
- assert columnValue != null : "Could not find data for column with id "
+ assert rowData.hasKey(id) : "Could not find data for column with id "
+ id;
+
+ final JsonValue columnValue = rowData.get(id);
+
return rendererConnector.decode(columnValue);
}
@@ -191,7 +184,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
/*
* An editor handler using Vaadin RPC to manage the editor state.
*/
- private class CustomEditorHandler implements EditorHandler<JSONObject> {
+ private class CustomEditorHandler implements EditorHandler<JsonObject> {
private EditorServerRpc rpc = getRpcProxy(EditorServerRpc.class);
@@ -245,7 +238,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
@Override
- public void bind(EditorRequest<JSONObject> request) {
+ public void bind(EditorRequest<JsonObject> request) {
if (!handleServerInitiated(request)) {
startRequest(request);
rpc.bind(request.getRowIndex());
@@ -253,7 +246,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
@Override
- public void save(EditorRequest<JSONObject> request) {
+ public void save(EditorRequest<JsonObject> request) {
if (!handleServerInitiated(request)) {
startRequest(request);
rpc.save(request.getRowIndex());
@@ -261,7 +254,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
@Override
- public void cancel(EditorRequest<JSONObject> request) {
+ public void cancel(EditorRequest<JsonObject> request) {
if (!handleServerInitiated(request)) {
// No startRequest as we don't get (or need)
// a confirmation from the server
@@ -270,7 +263,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
@Override
- public Widget getWidget(Grid.Column<?, JSONObject> column) {
+ public Widget getWidget(Grid.Column<?, JsonObject> column) {
assert column != null;
if (column instanceof CustomGridColumn) {
@@ -327,7 +320,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
*/
private Map<String, CustomGridColumn> columnIdToColumn = new HashMap<String, CustomGridColumn>();
- private AbstractRowHandleSelectionModel<JSONObject> selectionModel = createSelectionModel(SharedSelectionMode.NONE);
+ private AbstractRowHandleSelectionModel<JsonObject> selectionModel = createSelectionModel(SharedSelectionMode.NONE);
private Set<String> selectedKeys = new LinkedHashSet<String>();
private List<String> columnOrder = new ArrayList<String>();
@@ -342,18 +335,18 @@ public class GridConnector extends AbstractHasComponentsConnector implements
private RpcDataSource dataSource;
- private SelectionHandler<JSONObject> internalSelectionChangeHandler = new SelectionHandler<JSONObject>() {
+ private SelectionHandler<JsonObject> internalSelectionChangeHandler = new SelectionHandler<JsonObject>() {
@Override
- public void onSelect(SelectionEvent<JSONObject> event) {
+ public void onSelect(SelectionEvent<JsonObject> event) {
if (event.isBatchedSelection()) {
return;
}
if (!updatedFromState) {
- for (JSONObject row : event.getRemoved()) {
+ for (JsonObject row : event.getRemoved()) {
selectedKeys.remove(dataSource.getRowKey(row));
}
- for (JSONObject row : event.getAdded()) {
+ for (JsonObject row : event.getAdded()) {
selectedKeys.add(dataSource.getRowKey(row));
}
@@ -367,8 +360,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements
@Override
@SuppressWarnings("unchecked")
- public Grid<JSONObject> getWidget() {
- return (Grid<JSONObject>) super.getWidget();
+ public Grid<JsonObject> getWidget() {
+ return (Grid<JsonObject>) super.getWidget();
}
@Override
@@ -401,9 +394,9 @@ public class GridConnector extends AbstractHasComponentsConnector implements
getWidget().addSelectionHandler(internalSelectionChangeHandler);
- getWidget().addSortHandler(new SortHandler<JSONObject>() {
+ getWidget().addSortHandler(new SortHandler<JsonObject>() {
@Override
- public void sort(SortEvent<JSONObject> event) {
+ public void sort(SortEvent<JsonObject> event) {
List<SortOrder> order = event.getOrder();
String[] columnIds = new String[order.size()];
SortDirection[] directions = new SortDirection[order.size()];
@@ -425,10 +418,10 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
});
- getWidget().addSelectAllHandler(new SelectAllHandler<JSONObject>() {
+ getWidget().addSelectAllHandler(new SelectAllHandler<JsonObject>() {
@Override
- public void onSelectAll(SelectAllEvent<JSONObject> event) {
+ public void onSelectAll(SelectAllEvent<JsonObject> event) {
getRpcProxy(GridServerRpc.class).selectAll();
}
@@ -745,7 +738,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
return;
}
- AbstractRowHandleSelectionModel<JSONObject> model = createSelectionModel(mode);
+ AbstractRowHandleSelectionModel<JsonObject> model = createSelectionModel(mode);
if (!model.getClass().equals(selectionModel.getClass())) {
selectionModel = model;
getWidget().setSelectionModel(model);
@@ -808,8 +801,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements
// deselected row data. Some data is only stored as keys
updatedFromState = true;
getWidget().fireEvent(
- new SelectionEvent<JSONObject>(getWidget(),
- (List<JSONObject>) null, null, false));
+ new SelectionEvent<JsonObject>(getWidget(),
+ (List<JsonObject>) null, null, false));
}
}
@@ -833,15 +826,15 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
@SuppressWarnings("static-method")
- private AbstractRowHandleSelectionModel<JSONObject> createSelectionModel(
+ private AbstractRowHandleSelectionModel<JsonObject> createSelectionModel(
SharedSelectionMode mode) {
switch (mode) {
case SINGLE:
- return new SelectionModelSingle<JSONObject>();
+ return new SelectionModelSingle<JsonObject>();
case MULTI:
- return new SelectionModelMulti<JSONObject>();
+ return new SelectionModelMulti<JsonObject>();
case NONE:
- return new SelectionModelNone<JSONObject>();
+ return new SelectionModelNone<JsonObject>();
default:
throw new IllegalStateException("unexpected mode value: " + mode);
}
@@ -851,7 +844,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
* A workaround method for accessing the protected method
* {@code AbstractRowHandleSelectionModel.selectByHandle}
*/
- private native void selectByHandle(RowHandle<JSONObject> handle)
+ private native void selectByHandle(RowHandle<JsonObject> handle)
/*-{
var model = this.@com.vaadin.client.connectors.GridConnector::selectionModel;
model.@com.vaadin.client.widget.grid.selection.AbstractRowHandleSelectionModel::selectByHandle(*)(handle);
@@ -861,7 +854,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
* A workaround method for accessing the protected method
* {@code AbstractRowHandleSelectionModel.deselectByHandle}
*/
- private native void deselectByHandle(RowHandle<JSONObject> handle)
+ private native void deselectByHandle(RowHandle<JsonObject> handle)
/*-{
var model = this.@com.vaadin.client.connectors.GridConnector::selectionModel;
model.@com.vaadin.client.widget.grid.selection.AbstractRowHandleSelectionModel::deselectByHandle(*)(handle);
@@ -875,7 +868,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
* @return the key for the row at {@code index}
*/
public String getRowKey(int index) {
- final JSONObject row = dataSource.getRow(index);
+ final JsonObject row = dataSource.getRow(index);
final Object key = dataSource.getRowKey(row);
assert key instanceof String : "Internal key was not a String but a "
+ key.getClass().getSimpleName() + " (" + key + ")";
diff --git a/client/src/com/vaadin/client/connectors/ImageRendererConnector.java b/client/src/com/vaadin/client/connectors/ImageRendererConnector.java
index c0aaad07f9..341a98e9a8 100644
--- a/client/src/com/vaadin/client/connectors/ImageRendererConnector.java
+++ b/client/src/com/vaadin/client/connectors/ImageRendererConnector.java
@@ -15,16 +15,17 @@
*/
package com.vaadin.client.connectors;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
import com.google.web.bindery.event.shared.HandlerRegistration;
import com.vaadin.client.communication.JsonDecoder;
import com.vaadin.client.metadata.TypeDataStore;
-import com.vaadin.client.renderers.ImageRenderer;
import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
+import com.vaadin.client.renderers.ImageRenderer;
import com.vaadin.shared.communication.URLReference;
import com.vaadin.shared.ui.Connect;
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
/**
* A connector for {@link ImageRenderer}.
*
@@ -40,7 +41,7 @@ public class ImageRendererConnector extends ClickableRendererConnector<String> {
}
@Override
- public String decode(JSONValue value) {
+ public String decode(JsonValue value) {
return ((URLReference) JsonDecoder.decodeValue(
TypeDataStore.getType(URLReference.class), value, null,
getConnection())).getURL();
@@ -48,7 +49,7 @@ public class ImageRendererConnector extends ClickableRendererConnector<String> {
@Override
protected HandlerRegistration addClickHandler(
- RendererClickHandler<JSONObject> handler) {
+ RendererClickHandler<JsonObject> handler) {
return getRenderer().addClickHandler(handler);
}
}
diff --git a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
index 5f8a06ca10..754c87f0ca 100644
--- a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
+++ b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
@@ -18,11 +18,6 @@ package com.vaadin.client.connectors;
import java.util.ArrayList;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONParser;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.data.AbstractRemoteDataSource;
import com.vaadin.client.extensions.AbstractExtensionConnector;
@@ -32,6 +27,12 @@ import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.grid.GridState;
import com.vaadin.shared.ui.grid.Range;
+import elemental.json.Json;
+import elemental.json.JsonArray;
+import elemental.json.JsonObject;
+import elemental.json.JsonType;
+import elemental.json.JsonValue;
+
/**
* Connects a Vaadin server-side container data source to a Grid. This is
* currently implemented as an Extension hardcoded to support a specific
@@ -44,24 +45,21 @@ import com.vaadin.shared.ui.grid.Range;
@Connect(com.vaadin.data.RpcDataProviderExtension.class)
public class RpcDataSourceConnector extends AbstractExtensionConnector {
- public class RpcDataSource extends AbstractRemoteDataSource<JSONObject> {
+ public class RpcDataSource extends AbstractRemoteDataSource<JsonObject> {
protected RpcDataSource() {
registerRpc(DataProviderRpc.class, new DataProviderRpc() {
@Override
public void setRowData(int firstRow, String rowsJson) {
- JSONValue parsedJson = JSONParser.parseStrict(rowsJson);
- JSONArray rowArray = parsedJson.isArray();
- assert rowArray != null : "Was unable to parse JSON into an array: "
+ JsonValue parsedJson = Json.instance().parse(rowsJson);
+ assert parsedJson.getType() == JsonType.ARRAY : "Was unable to parse JSON into an array: "
+ parsedJson;
+ JsonArray rowArray = (JsonArray) parsedJson;
- ArrayList<JSONObject> rows = new ArrayList<JSONObject>(
- rowArray.size());
- for (int i = 0; i < rowArray.size(); i++) {
- JSONValue rowValue = rowArray.get(i);
- JSONObject rowObject = rowValue.isObject();
- assert rowObject != null : "Was unable to parse JSON into an object: "
- + rowValue;
+ ArrayList<JsonObject> rows = new ArrayList<JsonObject>(
+ rowArray.length());
+ for (int i = 0; i < rowArray.length(); i++) {
+ JsonObject rowObject = rowArray.getObject(i);
rows.add(rowObject);
}
@@ -89,7 +87,7 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector {
@Override
protected void requestRows(int firstRowIndex, int numberOfRows,
- RequestRowsCallback<JSONObject> callback) {
+ RequestRowsCallback<JsonObject> callback) {
/*
* If you're looking at this code because you want to learn how to
* use AbstactRemoteDataSource, please look somewhere else instead.
@@ -109,18 +107,17 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector {
}
@Override
- public String getRowKey(JSONObject row) {
- JSONString string = row.get(GridState.JSONKEY_ROWKEY).isString();
- if (string != null) {
- return string.stringValue();
+ public String getRowKey(JsonObject row) {
+ if (row.hasKey(GridState.JSONKEY_ROWKEY)) {
+ return row.getString(GridState.JSONKEY_ROWKEY);
} else {
return null;
}
}
- public RowHandle<JSONObject> getHandleByKey(Object key) {
- JSONObject row = new JSONObject();
- row.put(GridState.JSONKEY_ROWKEY, new JSONString((String) key));
+ public RowHandle<JsonObject> getHandleByKey(Object key) {
+ JsonObject row = Json.createObject();
+ row.put(GridState.JSONKEY_ROWKEY, (String) key);
return new RowHandleImpl(row, key);
}
diff --git a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java
index f76f5058c5..d48571452e 100644
--- a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java
+++ b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java
@@ -21,8 +21,8 @@ import java.util.Set;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
-import com.google.gwt.json.client.JSONArray;
import com.vaadin.client.ServerConnector;
+import com.vaadin.client.Util;
import com.vaadin.client.communication.JavaScriptMethodInvocation;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.extensions.AbstractExtensionConnector;
@@ -116,7 +116,7 @@ public class JavaScriptManagerConnector extends AbstractExtensionConnector {
}-*/;
public void sendRpc(String name, JsArray<JavaScriptObject> arguments) {
- Object[] parameters = new Object[] { name, new JSONArray(arguments) };
+ Object[] parameters = new Object[] { name, Util.jso2json(arguments) };
/*
* Must invoke manually as the RPC interface can't be used in GWT
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/MockApplicationConnection.java b/uitest/src/com/vaadin/tests/widgetset/client/MockApplicationConnection.java
index 4ee5b71387..0da1c6c775 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/MockApplicationConnection.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/MockApplicationConnection.java
@@ -18,13 +18,14 @@ package com.vaadin.tests.widgetset.client;
import java.util.Date;
import java.util.logging.Logger;
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ValueMap;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.tests.widgetset.server.csrf.ui.CsrfTokenDisabled;
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
/**
* Mock ApplicationConnection for several issues where we need to hack it.
*
@@ -71,9 +72,9 @@ public class MockApplicationConnection extends ApplicationConnection {
}
@Override
- protected void doUidlRequest(String uri, JSONObject payload) {
- JSONValue jsonValue = payload.get(ApplicationConstants.CSRF_TOKEN);
- lastCsrfTokenSent = jsonValue != null ? jsonValue.toString() : null;
+ protected void doUidlRequest(String uri, JsonObject payload) {
+ JsonValue jsonValue = payload.get(ApplicationConstants.CSRF_TOKEN);
+ lastCsrfTokenSent = jsonValue != null ? jsonValue.toJson() : null;
super.doUidlRequest(uri, payload);
}