aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-16 09:47:14 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-20 08:53:45 +0300
commit44758a2791a568f97a11e7da918444e4fffec84e (patch)
tree228ec297fa2362e5346ea59fdb672fae492f2613
parenta80335107906f1c41c1f42d2462dd838e8ea5b6c (diff)
downloadvaadin-framework-44758a2791a568f97a11e7da918444e4fffec84e.tar.gz
vaadin-framework-44758a2791a568f97a11e7da918444e4fffec84e.zip
Don't decode enum as an object (#9333)
-rw-r--r--server/src/com/vaadin/terminal/gwt/server/JsonCodec.java13
-rw-r--r--tests/testbench/com/vaadin/tests/serialization/SerializerTest.html40
-rw-r--r--tests/testbench/com/vaadin/tests/serialization/SerializerTest.java12
-rw-r--r--tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java11
-rw-r--r--tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java3
5 files changed, 54 insertions, 25 deletions
diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java
index 60197b0b3a..94d860a200 100644
--- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java
+++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java
@@ -165,6 +165,10 @@ public class JsonCodec implements Serializable {
} else if (targetType == JSONObject.class
|| targetType == JSONArray.class) {
return value;
+ } else if (Enum.class.isAssignableFrom(getClassForType(targetType))) {
+ Class<?> classForType = getClassForType(targetType);
+ return decodeEnum(classForType.asSubclass(Enum.class),
+ (String) value);
} else {
return decodeObject(targetType, (JSONObject) value,
connectorTracker);
@@ -420,9 +424,8 @@ public class JsonCodec implements Serializable {
}
}
- private static Object decodeEnum(Class<? extends Enum> cls, JSONObject value) {
- String enumIdentifier = String.valueOf(value);
- return Enum.valueOf(cls, enumIdentifier);
+ private static Object decodeEnum(Class<? extends Enum> cls, String value) {
+ return Enum.valueOf(cls, value);
}
private static String[] decodeStringArray(JSONArray jsonArray)
@@ -491,10 +494,6 @@ public class JsonCodec implements Serializable {
throws JSONException {
Class<?> targetClass = getClassForType(targetType);
- if (Enum.class.isAssignableFrom(targetClass)) {
- return decodeEnum(targetClass.asSubclass(Enum.class),
- serializedObject);
- }
try {
Object decodedObject = targetClass.newInstance();
diff --git a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html
index 3d52356cab..4417fabf14 100644
--- a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html
+++ b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html
@@ -18,90 +18,94 @@
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[16]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[17]</td>
<td>1. sendBoolean: false, false, [false, false, true, false, true, true]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[15]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[16]</td>
<td>2. sendByte: 5, -12, [3, 1, 2]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[14]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[15]</td>
<td>3. sendChar: Å, ∫, [a, b, c, d]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[13]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[14]</td>
<td>4. sendInt: 2, 5, [2147483647, 0]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[12]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[13]</td>
<td>5. sendLong: -57841235865, 577431841358, [57, 0]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[11]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[12]</td>
<td>6. sendFloat: 1.0000001, 3.14159, [-12.0, 0.0, 57.0]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[10]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[11]</td>
<td>7. sendDouble: 0.423310825130748, 5.859874482048838, [2.0, 1.7976931348623157E308, 4.9E-324]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[9]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[10]</td>
<td>8. sendString: Taegghiiiinnrsssstt‡</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[8]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[9]</td>
<td>9. sendConnector: com.vaadin.tests.widgetset.server.SerializerTestExtension</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[7]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[8]</td>
<td>10. sendBean: ComplexTestBean [innerBean1=SimpleTestBean(1), innerBean2=SimpleTestBean(3), innerBeanCollection=[SimpleTestBean(6), SimpleTestBean(0)], privimite=6], SimpleTestBean(0), [SimpleTestBean(7)]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[6]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[7]</td>
<td>11. sendNull: null, Not null</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[5]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[6]</td>
<td>12. sendNestedArray: [[7, 5]], [[SimpleTestBean(2)], [SimpleTestBean(4)]]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[4]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[5]</td>
<td>13. sendList: [-234, 5, 8], class com.vaadin.tests.widgetset.server.SerializerTestExtension, class com.vaadin.tests.serialization.SerializerTest, [SimpleTestBean(-568), SimpleTestBean(234)]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[3]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[4]</td>
<td>14. sendArrayList: [[2], [2]], [[2, 1], [2, 3]], [[SimpleTestBean(7)]]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[3]</td>
<td>15. sendSet: [-12, -7, -4], class com.vaadin.tests.serialization.SerializerTest, [SimpleTestBean(2), SimpleTestBean(3)]</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2]</td>
<td>16. sendMap: {a=null}, [com.vaadin.tests.widgetset.server.SerializerTestExtension=false], [2=com.vaadin.tests.widgetset.server.SerializerTestExtension], {SimpleTestBean(4)=SimpleTestBean(-4), SimpleTestBean(-5)=SimpleTestBean(5)}</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td>
<td>17. sendWrappedGenerics: {[SimpleTestBean(1)]={1=[SimpleTestBean(42)]}}</td>
</tr>
-
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>18. sendEnum: PREFORMATTED, [XHTML, RAW], [PREFORMATTED, XML]</td>
+</tr>
</tbody></table>
</body>
</html>
diff --git a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java
index da4b5dd7d9..a301ecf828 100644
--- a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java
+++ b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java
@@ -28,6 +28,7 @@ import java.util.Set;
import com.vaadin.annotations.Widgetset;
import com.vaadin.shared.Connector;
+import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.terminal.WrappedRequest;
import com.vaadin.tests.components.AbstractTestRoot;
import com.vaadin.tests.util.Log;
@@ -122,6 +123,10 @@ public class SerializerTest extends AbstractTestRoot {
}
});
+ rpc.sendEnum(ContentMode.TEXT, new ContentMode[] {
+ ContentMode.PREFORMATTED, ContentMode.XML },
+ Arrays.asList(ContentMode.XHTML, ContentMode.RAW));
+
testExtension.registerRpc(new SerializerTestRpc() {
@Override
public void sendBoolean(boolean value, Boolean boxedValue,
@@ -288,6 +293,13 @@ public class SerializerTest extends AbstractTestRoot {
log.log("sendWrappedGenerics: " + generics.toString());
}
+ @Override
+ public void sendEnum(ContentMode contentMode, ContentMode[] array,
+ List<ContentMode> list) {
+ log.log("sendEnum: " + contentMode + ", "
+ + Arrays.toString(array) + ", " + list);
+ }
+
});
}
diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java
index 3977ff7f71..9fb6807bb7 100644
--- a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java
+++ b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java
@@ -28,6 +28,7 @@ import java.util.Set;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.terminal.gwt.client.communication.RpcProxy;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.extensions.AbstractExtensionConnector;
@@ -231,6 +232,16 @@ public class SerializerTestConnector extends AbstractExtensionConnector {
objectListArray[0] }, new List[] { Collections
.singletonList(beanListArray[0].get(0)) });
}
+
+ @Override
+ public void sendEnum(ContentMode contentMode, ContentMode[] array,
+ List<ContentMode> list) {
+ ContentMode nextContentMode = ContentMode.values()[contentMode
+ .ordinal() + 1];
+ rpc.sendEnum(nextContentMode,
+ list.toArray(new ContentMode[list.size()]),
+ Arrays.asList(array));
+ }
});
}
diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java
index 47a26b7408..eb3a20e90e 100644
--- a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java
+++ b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java
@@ -23,6 +23,7 @@ import java.util.Set;
import com.vaadin.shared.Connector;
import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.ServerRpc;
+import com.vaadin.shared.ui.label.ContentMode;
@SuppressWarnings("javadoc")
public interface SerializerTestRpc extends ServerRpc, ClientRpc {
@@ -73,4 +74,6 @@ public interface SerializerTestRpc extends ServerRpc, ClientRpc {
public void sendWrappedGenerics(
Map<Set<SimpleTestBean>, Map<Integer, List<SimpleTestBean>>> generics);
+ public void sendEnum(ContentMode contentMode, ContentMode[] array, List<ContentMode> list);
+
}