]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merge branch 'rpcArray'
authorLeif Åstrand <leif@vaadin.com>
Mon, 25 Jun 2012 09:43:51 +0000 (12:43 +0300)
committerLeif Åstrand <leif@vaadin.com>
Mon, 25 Jun 2012 09:43:51 +0000 (12:43 +0300)
Conflicts:
src/com/vaadin/terminal/gwt/server/JsonCodec.java

1  2 
src/com/vaadin/terminal/gwt/server/JsonCodec.java

index 4b470f72151174e0da0316b2b9755d706e5006c0,4fb7681e4a0f76532faded33ce8a12b2058ca9bc..d3a2ef56f888cd681444e5a0bbac4431ceae8562
@@@ -125,6 -128,16 +130,16 @@@ public class JsonCodec implements Seria
          // Try to decode object using fields
          if (value == JSONObject.NULL) {
              return null;
 -                    application);
+         } else if (targetType == byte.class || targetType == Byte.class) {
+             return Byte.valueOf(String.valueOf(value));
+         } else if (targetType == char.class || targetType == Character.class) {
+             return Character.valueOf(String.valueOf(value).charAt(0));
+         } else if (targetType instanceof Class<?>
+                 && ((Class<?>) targetType).isArray()) {
+             // Legacy Object[] and String[] handled elsewhere, this takes care
+             // of generic arrays
+             return decodeArray((Class<?>) targetType, (JSONArray) value,
++                    connectorTracker);
          } else if (targetType == JSONObject.class
                  || targetType == JSONArray.class) {
              return value;
          }
      }
  
 -            Application application) throws JSONException {
+     private static Object decodeArray(Class<?> targetType, JSONArray value,
 -                    value.get(i), application);
++            ConnectorTracker connectorTracker) throws JSONException {
+         Class<?> componentType = targetType.getComponentType();
+         Object array = Array.newInstance(componentType, value.length());
+         for (int i = 0; i < value.length(); i++) {
+             Object decodedValue = decodeInternalOrCustomType(componentType,
++                    value.get(i), connectorTracker);
+             Array.set(array, i, decodedValue);
+         }
+         return array;
+     }
      /**
       * Decodes a value that is of an internal type.
       * <p>
          String stringValue = String.valueOf(encodedJsonValue);
  
          if (JsonEncoder.VTYPE_CONNECTOR.equals(transportType)) {
 -            return application.getConnector(stringValue);
 +            return connectorTracker.getConnector(stringValue);
          }
  
-         // Standard Java types
+         // Legacy types
  
          if (JsonEncoder.VTYPE_STRING.equals(transportType)) {
              return stringValue;
          } else if (value instanceof Collection) {
              Collection<?> collection = (Collection<?>) value;
              JSONArray jsonArray = encodeCollection(valueType, collection,
 -                    application);
 +                    connectorTracker);
              return jsonArray;
-         } else if (value instanceof Object[]) {
-             Object[] array = (Object[]) value;
-             JSONArray jsonArray = encodeArrayContents(array, connectorTracker);
+         } else if (valueType instanceof Class<?>
+                 && ((Class<?>) valueType).isArray()) {
 -            JSONArray jsonArray = encodeArrayContents(value, application);
++            JSONArray jsonArray = encodeArrayContents(value, connectorTracker);
              return jsonArray;
          } else if (value instanceof Map) {
              Object jsonMap = encodeMap(valueType, (Map<?, ?>) value,
          return e.name();
      }
  
-     private static JSONArray encodeArrayContents(Object[] array,
+     private static JSONArray encodeArrayContents(Object array,
 -            Application application) throws JSONException {
 +            ConnectorTracker connectorTracker) throws JSONException {
          JSONArray jsonArray = new JSONArray();
-         for (Object o : array) {
-             jsonArray.put(encode(o, null, null, connectorTracker));
+         Class<?> componentType = array.getClass().getComponentType();
+         for (int i = 0; i < Array.getLength(array); i++) {
+             jsonArray.put(encode(Array.get(array, i), null, componentType,
 -                    application));
++                    connectorTracker));
          }
          return jsonArray;
      }