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);
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,
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);
.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();
}
}
- 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 {
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);
}
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();
}
}