summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-12-17 09:43:45 +0000
committerVaadin Code Review <review@vaadin.com>2012-12-17 09:43:45 +0000
commit2daaea1fb20e112c6c14a2f94c2685bbff4ce0e8 (patch)
treeb6a608ecb79ec2705eafe8f3c130e3b9a06248bf
parenta2610c8e6752b351929316e59c4b287314ad96b2 (diff)
parent6511a066c124a8c336bd299c6200c99fe0c0b08c (diff)
downloadvaadin-framework-2daaea1fb20e112c6c14a2f94c2685bbff4ce0e8.tar.gz
vaadin-framework-2daaea1fb20e112c6c14a2f94c2685bbff4ce0e8.zip
Merge "Support null values in legacy messages (#9254)"
-rw-r--r--server/src/com/vaadin/server/JsonCodec.java4
-rw-r--r--server/tests/src/com/vaadin/server/JSONSerializerTest.java27
2 files changed, 31 insertions, 0 deletions
diff --git a/server/src/com/vaadin/server/JsonCodec.java b/server/src/com/vaadin/server/JsonCodec.java
index 89ef060ef0..f7cbe79fdb 100644
--- a/server/src/com/vaadin/server/JsonCodec.java
+++ b/server/src/com/vaadin/server/JsonCodec.java
@@ -185,6 +185,7 @@ public class JsonCodec implements Serializable {
registerType(HashMap.class, JsonConstants.VTYPE_MAP);
registerType(List.class, JsonConstants.VTYPE_LIST);
registerType(Set.class, JsonConstants.VTYPE_SET);
+ registerType(Void.class, JsonConstants.VTYPE_NULL);
}
private static void registerType(Class<?> type, String transportType) {
@@ -325,6 +326,9 @@ public class JsonCodec implements Serializable {
if (encodedJsonValue == JSONObject.NULL) {
return null;
+ } else if (targetType == Void.class) {
+ throw new JSONException(
+ "Something other than null was encoded for a null type");
}
// UidlValue
diff --git a/server/tests/src/com/vaadin/server/JSONSerializerTest.java b/server/tests/src/com/vaadin/server/JSONSerializerTest.java
index fc02c13781..981f74a2a4 100644
--- a/server/tests/src/com/vaadin/server/JSONSerializerTest.java
+++ b/server/tests/src/com/vaadin/server/JSONSerializerTest.java
@@ -16,13 +16,20 @@ package com.vaadin.server;
* the License.
*/
import java.lang.reflect.Type;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import com.vaadin.server.JsonCodec.BeanProperty;
+import com.vaadin.shared.communication.UidlValue;
import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState;
/**
@@ -72,6 +79,26 @@ public class JSONSerializerTest extends TestCase {
ensureDecodedCorrectly(stateToStringMap, encodedMap, mapType);
}
+ public void testNullLegacyValue() throws JSONException {
+ JSONArray inputArray = new JSONArray(
+ Arrays.asList("n", JSONObject.NULL));
+ UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
+ UidlValue.class, true, inputArray, null);
+ assertNull(decodedObject.getValue());
+ }
+
+ public void testNullTypeOtherValue() {
+ try {
+ JSONArray inputArray = new JSONArray(Arrays.asList("n", "a"));
+ UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
+ UidlValue.class, true, inputArray, null);
+
+ throw new AssertionFailedError("No JSONException thrown");
+ } catch (JSONException e) {
+ // Should throw exception
+ }
+ }
+
private void ensureDecodedCorrectly(Object original, Object encoded,
Type type) throws Exception {
Object serverSideDecoded = JsonCodec.decodeInternalOrCustomType(type,