summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-12-18 15:07:21 +0200
committerVaadin Code Review <review@vaadin.com>2012-12-18 13:35:12 +0000
commita6ffd484283353825470988bf2d13093685d2761 (patch)
tree4beab888aac6ecf37a318d2eb68f1dd433acbf1e /server
parentca967cbe1d927d7acf5cb72683265557e0b46360 (diff)
downloadvaadin-framework-a6ffd484283353825470988bf2d13093685d2761.tar.gz
vaadin-framework-a6ffd484283353825470988bf2d13093685d2761.zip
Encode all values based on declared type (#10549)
* ServerRpc encoding uses type data from the interface * Beans encoded on the server use reflection based on declared type * Remove row numbers to enable adding test without changing old indices * Update test to send non-primitive map values Change-Id: I0462b547cb7de252564b3569420b0b24cee4515f
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/JsonCodec.java13
1 files changed, 8 insertions, 5 deletions
diff --git a/server/src/com/vaadin/server/JsonCodec.java b/server/src/com/vaadin/server/JsonCodec.java
index f7cbe79fdb..aeda8f622f 100644
--- a/server/src/com/vaadin/server/JsonCodec.java
+++ b/server/src/com/vaadin/server/JsonCodec.java
@@ -666,10 +666,13 @@ public class JsonCodec implements Serializable {
return encodeEnum((Enum<?>) value, connectorTracker);
} else if (value instanceof JSONArray || value instanceof JSONObject) {
return new EncodeResult(value);
- } else {
+ } else if (valueType instanceof Class<?>) {
// Any object that we do not know how to encode we encode by looping
// through fields
- return encodeObject(value, (JSONObject) diffState, connectorTracker);
+ return encodeObject(value, (Class<?>) valueType,
+ (JSONObject) diffState, connectorTracker);
+ } else {
+ throw new JSONException("Can not encode " + valueType);
}
}
@@ -687,14 +690,14 @@ public class JsonCodec implements Serializable {
return properties;
}
- private static EncodeResult encodeObject(Object value,
+ private static EncodeResult encodeObject(Object value, Class<?> valueType,
JSONObject referenceValue, ConnectorTracker connectorTracker)
throws JSONException {
JSONObject encoded = new JSONObject();
JSONObject diff = new JSONObject();
try {
- for (BeanProperty property : getProperties(value.getClass())) {
+ for (BeanProperty property : getProperties(valueType)) {
String fieldName = property.getName();
// We can't use PropertyDescriptor.getPropertyType() as it does
// not support generics
@@ -704,7 +707,7 @@ public class JsonCodec implements Serializable {
if (encoded.has(fieldName)) {
throw new RuntimeException(
"Can't encode "
- + value.getClass().getName()
+ + valueType.getName()
+ " as it has multiple properties with the name "
+ fieldName.toLowerCase()
+ ". This can happen if there are getters and setters for a public field (the framework can't know which to ignore) or if there are properties with only casing distinguishing between the names (e.g. getFoo() and getFOO())");