summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc@vaadin.com>2012-04-17 09:19:36 +0300
committerMarc Englund <marc@vaadin.com>2012-04-17 09:21:04 +0300
commit6e50774cd0c9edc11fa16b8178a637461046cfd1 (patch)
treec902d49e03d92c2d3e0542b963be9b21d34b64ff
parent0290e81095f08371218158872a9c3e3b76fb3991 (diff)
downloadvaadin-framework-6e50774cd0c9edc11fa16b8178a637461046cfd1.tar.gz
vaadin-framework-6e50774cd0c9edc11fa16b8178a637461046cfd1.zip
Fixes #8673 (some fields not en/decoded correctly) by using the setter/getter name w/o altering case.
-rw-r--r--src/com/vaadin/terminal/gwt/server/JsonCodec.java28
-rw-r--r--src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java14
2 files changed, 29 insertions, 13 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/src/com/vaadin/terminal/gwt/server/JsonCodec.java
index 304267d4b9..1824a16fb2 100644
--- a/src/com/vaadin/terminal/gwt/server/JsonCodec.java
+++ b/src/com/vaadin/terminal/gwt/server/JsonCodec.java
@@ -271,9 +271,9 @@ public class JsonCodec implements Serializable {
try {
for (PropertyDescriptor pd : Introspector.getBeanInfo(
value.getClass()).getPropertyDescriptors()) {
- String fieldName = pd.getName();
Class<?> fieldType = pd.getPropertyType();
- if (pd.getReadMethod() == null || pd.getWriteMethod() == null) {
+ String fieldName = getTransportFieldName(pd);
+ if (fieldName == null) {
continue;
}
Method getterMethod = pd.getReadMethod();
@@ -288,6 +288,24 @@ public class JsonCodec implements Serializable {
return jsonMap;
}
+ /**
+ * Returns the name that should be used as field name in the JSON. We strip
+ * "set" from the setter, keeping the result - this is easy to do on both
+ * server and client, avoiding some issues with cASE. E.g setZIndex()
+ * becomes "ZIndex". Also ensures that both getter and setter are present,
+ * returning null otherwise.
+ *
+ * @param pd
+ * @return the name to be used or null if both getter and setter are not
+ * found.
+ */
+ private static String getTransportFieldName(PropertyDescriptor pd) {
+ if (pd.getReadMethod() == null || pd.getWriteMethod() == null) {
+ return null;
+ }
+ return pd.getWriteMethod().getName().substring(3);
+ }
+
private static Object decodeObject(String type,
JSONObject serializedObject, Application application)
throws JSONException {
@@ -299,11 +317,11 @@ public class JsonCodec implements Serializable {
Object decodedObject = cls.newInstance();
for (PropertyDescriptor pd : Introspector.getBeanInfo(cls)
.getPropertyDescriptors()) {
- if (pd.getReadMethod() == null || pd.getWriteMethod() == null) {
+
+ String fieldName = getTransportFieldName(pd);
+ if (fieldName == null) {
continue;
}
-
- String fieldName = pd.getName();
JSONArray encodedObject = serializedObject
.getJSONArray(fieldName);
pd.getWriteMethod().invoke(decodedObject,
diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java
index 43496a5451..18bc5439ec 100644
--- a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java
+++ b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java
@@ -130,8 +130,7 @@ public class SerializerGenerator extends Generator {
for (JMethod setterMethod : getSetters(beanType)) {
String setterName = setterMethod.getName();
- String capitalizedFieldName = setterName.substring(3);
- String fieldName = decapitalize(capitalizedFieldName);
+ String fieldName = setterName.substring(3); // setZindex() -> ZIndex
String getterName = findGetter(beanType, setterMethod);
if (getterName == null) {
@@ -162,14 +161,13 @@ public class SerializerGenerator extends Generator {
+ beanQualifiedSourceName + ".class);");
for (JMethod method : getSetters(beanType)) {
String setterName = method.getName();
- String capitalizedFieldName = setterName.substring(3);
- String fieldName = decapitalize(capitalizedFieldName);
+ String fieldName = setterName.substring(3); // setZIndex() -> ZIndex
JType setterParameterType = method.getParameterTypes()[0];
logger.log(Type.DEBUG, "* Processing field " + fieldName + " in "
+ beanQualifiedSourceName + " (" + beanType.getName() + ")");
- String jsonFieldName = "json" + capitalizedFieldName;
+ String jsonFieldName = "json" + fieldName;
// JSONArray jsonHeight = (JSONArray) jsonValue.get("height");
sourceWriter.println("JSONArray " + jsonFieldName
+ " = (JSONArray) jsonValue.get(\"" + fieldName + "\");");
@@ -209,12 +207,12 @@ public class SerializerGenerator extends Generator {
private String findGetter(JClassType beanType, JMethod setterMethod) {
JType setterParameterType = setterMethod.getParameterTypes()[0];
- String capitalizedFieldName = setterMethod.getName().substring(3);
+ String fieldName = setterMethod.getName().substring(3);
if (setterParameterType.getQualifiedSourceName().equals(
boolean.class.getName())) {
- return "is" + capitalizedFieldName;
+ return "is" + fieldName;
} else {
- return "get" + capitalizedFieldName;
+ return "get" + fieldName;
}
}