@@ -88,8 +88,8 @@ public class JsonEncoder { | |||
if (restrictToInternalTypes) { | |||
// Enums are encoded as strings in Vaadin 6 so we still do that | |||
// for backwards copmatibility. | |||
return encode(value.toString(), restrictToInternalTypes, | |||
connectorMap, connection); | |||
return encode(new UidlValue(value.toString()), | |||
restrictToInternalTypes, connectorMap, connection); | |||
} else { | |||
Enum e = (Enum) value; | |||
return encodeEnum(e, connectorMap, connection); | |||
@@ -140,6 +140,15 @@ public class JsonEncoder { | |||
JSONObject jsonMap = new JSONObject(); | |||
for (Object mapKey : map.keySet()) { | |||
Object mapValue = map.get(mapKey); | |||
if (restrictToInternalTypes) { | |||
if (!(mapKey instanceof String)) { | |||
throw new IllegalStateException( | |||
"Only string keys supported for legacy maps"); | |||
} | |||
// Wrap in UidlValue to send explicit type info | |||
mapKey = new UidlValue(mapKey); | |||
mapValue = new UidlValue(mapValue); | |||
} | |||
JSONValue encodedKey = encode(mapKey, restrictToInternalTypes, | |||
connectorMap, connection); | |||
JSONValue encodedValue = encode(mapValue, restrictToInternalTypes, | |||
@@ -161,9 +170,13 @@ public class JsonEncoder { | |||
JSONArray jsonArray = new JSONArray(); | |||
for (int i = 0; i < array.length; ++i) { | |||
// TODO handle object graph loops? | |||
Object value = array[i]; | |||
if (restrictToInternalTypes) { | |||
value = new UidlValue(value); | |||
} | |||
jsonArray.set( | |||
i, | |||
encode(array[i], restrictToInternalTypes, connectorMap, | |||
encode(value, restrictToInternalTypes, connectorMap, | |||
connection)); | |||
} | |||
return combineTypeAndValue(VTYPE_ARRAY, jsonArray); |
@@ -1632,7 +1632,8 @@ public abstract class AbstractCommunicationManager implements Serializable { | |||
.decodeInternalType(String.class, true, | |||
parametersJson.getJSONArray(0), application); | |||
UidlValue uidlValue = (UidlValue) JsonCodec.decodeInternalType( | |||
parametersJson.getJSONArray(1), application); | |||
UidlValue.class, true, parametersJson.getJSONArray(1), | |||
application); | |||
Object value = uidlValue.getValue(); | |||
@@ -96,31 +96,10 @@ public class JsonCodec implements Serializable { | |||
} | |||
} | |||
public static String getTransportType(JSONArray encodedValue) | |||
throws JSONException { | |||
return encodedValue.getString(0); | |||
} | |||
private static Class<?> getType(String transportType) { | |||
return transportTypeToType.get(transportType); | |||
} | |||
/** | |||
* Decodes the given value and type, restricted to using only internal | |||
* types. | |||
* | |||
* @param valueAndType | |||
* @param application | |||
* @throws JSONException | |||
*/ | |||
@Deprecated | |||
public static Object decodeInternalType(JSONArray valueAndType, | |||
Application application) throws JSONException { | |||
String transportType = getTransportType(valueAndType); | |||
return decodeInternalType(getType(transportType), true, valueAndType, | |||
application); | |||
} | |||
public static Object decodeInternalOrCustomType(Type targetType, | |||
JSONArray valueAndType, Application application) | |||
throws JSONException { | |||
@@ -258,10 +237,10 @@ public class JsonCodec implements Serializable { | |||
Application application) throws JSONException { | |||
String type = encodedJsonValue.getString(0); | |||
// Fake format used by decode method | |||
JSONArray valueAndType = new JSONArray(Arrays.asList(type, | |||
encodedJsonValue.get(1))); | |||
Object decodedValue = decodeInternalType(valueAndType, application); | |||
Object decodedValue = decodeInternalType(getType(type), true, | |||
valueAndType, application); | |||
return new UidlValue(decodedValue); | |||
} | |||
@@ -322,9 +301,11 @@ public class JsonCodec implements Serializable { | |||
return decodeInternalOrCustomType(childType, encodedValueAndType, | |||
application); | |||
} else { | |||
// Only internal types when not enforcing a given type to avoid | |||
// security issues | |||
return decodeInternalType(encodedValueAndType, application); | |||
// Only UidlValue when not enforcing a given type to avoid security | |||
// issues | |||
UidlValue decodeInternalType = (UidlValue) decodeInternalType( | |||
UidlValue.class, true, encodedValueAndType, application); | |||
return decodeInternalType.getValue(); | |||
} | |||
} | |||