You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/11/23 14:27:59 UTC
svn commit: r1038102 - in /pivot/trunk/core:
src/org/apache/pivot/json/JSONSerializer.java
test/org/apache/pivot/json/test/sample.json
Author: gbrown
Date: Tue Nov 23 13:27:59 2010
New Revision: 1038102
URL: http://svn.apache.org/viewvc?rev=1038102&view=rev
Log:
When binding JSON to a bean structure, ignore missing bean properties.
Modified:
pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java
pivot/trunk/core/test/org/apache/pivot/json/test/sample.json
Modified: pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java?rev=1038102&r1=1038101&r2=1038102&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java Tue Nov 23 13:27:59 2010
@@ -737,8 +737,21 @@ public class JSONSerializer implements S
// Move to the first character after ':'
c = reader.read();
- dictionary.put(key, readValue(reader, (valueType == null) ?
- ((BeanAdapter)dictionary).getGenericType(key) : valueType));
+
+ if (valueType == null) {
+ // The map is a bean instance; get the generic type of the property
+ Type genericValueType = ((BeanAdapter)dictionary).getGenericType(key);
+
+ if (genericValueType != null) {
+ // Set the value in the bean
+ dictionary.put(key, readValue(reader, genericValueType));
+ } else {
+ // The property does not exist; ignore this value
+ readValue(reader, Object.class);
+ }
+ } else {
+ dictionary.put(key, readValue(reader, valueType));
+ }
skipWhitespaceAndComments(reader);
Modified: pivot/trunk/core/test/org/apache/pivot/json/test/sample.json
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/json/test/sample.json?rev=1038102&r1=1038101&r2=1038102&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/json/test/sample.json (original)
+++ pivot/trunk/core/test/org/apache/pivot/json/test/sample.json Tue Nov 23 13:27:59 2010
@@ -19,5 +19,6 @@
c: false,
d: ["1", "2", "3"],
e: {f: 4, g: 5, h: 6},
- "i": { a: 200, b: "Goodbye", c: true}
+ "i": { a: 200, b: "Goodbye", c: true},
+ j: 200
}