Package com.google.gwt.json.client

Examples of com.google.gwt.json.client.JSONArray


    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) {
                return new HashMap<Object, Object>();
            }
        }

        Type keyType = type.getParameterTypes()[0];
View Full Code Here


    private static Map<Object, Object> decodeObjectMap(Type keyType,
            Type valueType, JSONValue 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);

        assert (keys.size() == values.size());

        for (int i = 0; i < keys.size(); i++) {
            Object decodedKey = decodeValue(keyType, keys.get(i), null,
                    connection);
            Object decodedValue = decodeValue(valueType, values.get(i), null,
                    connection);

            map.put(decodedKey, decodedValue);
        }
View Full Code Here

            return JSONNull.getInstance();
        } else if (value instanceof JSONValue) {
            return (JSONValue) value;
        } else if (value instanceof String[]) {
            String[] array = (String[]) value;
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < array.length; ++i) {
                jsonArray.set(i, new JSONString(array[i]));
            }
            return jsonArray;
        } else if (value instanceof String) {
            return new JSONString((String) value);
        } else if (value instanceof Boolean) {
View Full Code Here

    private static JSONValue encodeVariableChange(UidlValue uidlValue,
            ApplicationConnection connection) {
        Object value = uidlValue.getValue();

        JSONArray jsonArray = new JSONArray();
        String transportType = getTransportType(value);
        if (transportType == null) {
            /*
             * This should not happen unless you try to send an unsupported type
             * in a legacy variable change from the client to the server.
             */
            String valueType = null;
            if (value != null) {
                valueType = value.getClass().getName();
            }
            throw new IllegalArgumentException("Cannot encode object of type "
                    + valueType);
        }
        jsonArray.set(0, new JSONString(transportType));
        jsonArray.set(1, encode(value, null, connection));

        return jsonArray;
    }
View Full Code Here

         * scheme based on actual type of first key. We can't do this if there's
         * no first key, so instead we send some special value that the
         * server-side decoding must check for. (see #8906)
         */
        if (map.isEmpty()) {
            return new JSONArray();
        }

        Object firstKey = map.keySet().iterator().next();
        if (firstKey instanceof String) {
            return encodeStringMap(map, type, connection);
View Full Code Here

        }
    }

    private static JSONValue encodeObjectMap(Map<Object, Object> map,
            Type type, ApplicationConnection connection) {
        JSONArray keys = new JSONArray();
        JSONArray values = new JSONArray();

        assert type != null : "Should only be used for non-legacy types";

        for (Entry<?, ?> entry : map.entrySet()) {
            keys.set(keys.size(),
                    encodeChildValue(entry.getKey(), type, 0, connection));
            values.set(values.size(),
                    encodeChildValue(entry.getValue(), type, 1, connection));
        }

        JSONArray keysAndValues = new JSONArray();
        keysAndValues.set(0, keys);
        keysAndValues.set(1, values);

        return keysAndValues;
    }
View Full Code Here

        return new JSONString(e.toString());
    }

    private static JSONValue encodeLegacyObjectArray(Object[] array,
            ApplicationConnection connection) {
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < array.length; ++i) {
            // TODO handle object graph loops?
            Object value = array[i];
            jsonArray.set(i, encode(value, null, connection));
        }
        return jsonArray;
    }
View Full Code Here

        return jsonArray;
    }

    private static JSONValue encodeCollection(Collection collection, Type type,
            ApplicationConnection connection) {
        JSONArray jsonArray = new JSONArray();
        int idx = 0;
        for (Object o : collection) {
            JSONValue encodedObject = encodeChildValue(o, type, 0, connection);
            jsonArray.set(idx++, encodedObject);
        }
        if (collection instanceof Set) {
            return jsonArray;
        } else if (collection instanceof List) {
            return jsonArray;
View Full Code Here

            (new $wnd.Function(script)).apply($wnd);
        }
    }-*/;

    public void sendRpc(String name, JsArray<JavaScriptObject> arguments) {
        Object[] parameters = new Object[] { name, new JSONArray(arguments) };

        /*
         * Must invoke manually as the RPC interface can't be used in GWT
         * because of the JSONArray parameter
         */
 
View Full Code Here

        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);

        ServerConnector connector = connectorMap.getConnector(connectorId);

        MethodInvocation invocation = new MethodInvocation(connectorId,
                interfaceName, methodName);
View Full Code Here

TOP

Related Classes of com.google.gwt.json.client.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.