diff options
author | Artur Signell <artur@vaadin.com> | 2012-03-09 11:47:09 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-03-13 18:10:40 +0200 |
commit | 77f399a27e1d06b7a9fa7bd699ce1176ba0b40ef (patch) | |
tree | f161330f7918ade71343ac8655c3ba93de7a4cd7 /src/com/vaadin/terminal/gwt/server/JsonCodec.java | |
parent | 618aa03e04d399b53a1815181ab024fbc3e4bf15 (diff) | |
download | vaadin-framework-77f399a27e1d06b7a9fa7bd699ce1176ba0b40ef.tar.gz vaadin-framework-77f399a27e1d06b7a9fa7bd699ce1176ba0b40ef.zip |
#8510 Support using Resources through URLReference/ResourceReference in
shared state and RPC calls
Diffstat (limited to 'src/com/vaadin/terminal/gwt/server/JsonCodec.java')
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/JsonCodec.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/src/com/vaadin/terminal/gwt/server/JsonCodec.java index 350a70d9d4..0a617470a5 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -153,6 +153,12 @@ public class JsonCodec implements Serializable { */ public static JSONArray encode(Object value, PaintableIdMapper idMapper) throws JSONException { + return encode(value, null, idMapper); + } + + public static JSONArray encode(Object value, Class<?> valueType, + PaintableIdMapper idMapper) throws JSONException { + if (null == value) { // TODO as undefined type? return combineTypeAndValue(JsonEncoder.VTYPE_UNDEFINED, @@ -188,7 +194,11 @@ public class JsonCodec implements Serializable { } else { // Any object that we do not know how to encode we encode by looping // through fields - return combineTypeAndValue(value.getClass().getCanonicalName(), + if (valueType == null) { + valueType = value.getClass(); + } + + return combineTypeAndValue(valueType.getCanonicalName(), encodeObject(value, idMapper)); } } @@ -201,12 +211,13 @@ public class JsonCodec implements Serializable { for (PropertyDescriptor pd : Introspector.getBeanInfo( value.getClass()).getPropertyDescriptors()) { String fieldName = pd.getName(); + Class<?> fieldType = pd.getPropertyType(); if (pd.getReadMethod() == null || pd.getWriteMethod() == null) { continue; } Method getterMethod = pd.getReadMethod(); Object fieldValue = getterMethod.invoke(value, null); - jsonMap.put(fieldName, encode(fieldValue, idMapper)); + jsonMap.put(fieldName, encode(fieldValue, fieldType, idMapper)); } } catch (Exception e) { // TODO: Should exceptions be handled in a different way? |