Repository: wicket
Updated Branches:
  refs/heads/wicket-7.x 573b01b44 -> 294423916


Fixed JSONObject constructor to throw checked exceptions

* see https://github.com/apache/wicket/pull/195#issuecomment-270600508

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/29442391
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/29442391
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/29442391

Branch: refs/heads/wicket-7.x
Commit: 294423916e0ece7be3819e9a7cae1671af38a0bf
Parents: 573b01b
Author: Tobias Soloschenko <[email protected]>
Authored: Sun Jan 15 14:44:14 2017 +0100
Committer: Tobias Soloschenko <[email protected]>
Committed: Sun Jan 15 14:44:14 2017 +0100

----------------------------------------------------------------------
 .../org/apache/wicket/ajax/json/JSONObject.java | 29 +++++++++++++-------
 1 file changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/29442391/wicket-core/src/main/java/org/apache/wicket/ajax/json/JSONObject.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/json/JSONObject.java 
b/wicket-core/src/main/java/org/apache/wicket/ajax/json/JSONObject.java
index 3f94a86..0d147ea 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/json/JSONObject.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/json/JSONObject.java
@@ -212,19 +212,28 @@ public class JSONObject {
         }
     }
 
-    public JSONObject(Object bean) throws IntrospectionException, 
InvocationTargetException, IllegalAccessException {
-        this(propertiesAsMap(bean));
+    /**
+     * Creates a json object from a bean
+     * @param bean the been to create the json object from
+     * @throws JSONException If there is an exception while reading the bean
+     */
+    public JSONObject(Object bean) throws JSONException {
+               this(propertiesAsMap(bean));
     }
 
     private static Map<String, Object> propertiesAsMap(Object bean)
-            throws IntrospectionException, IllegalAccessException, 
InvocationTargetException {
-        PropertyDescriptor[] properties = 
Introspector.getBeanInfo(bean.getClass(), Object.class)
-                .getPropertyDescriptors();
-        Map<String, Object> props = new TreeMap<String, Object>();
-        for (int i = 0; i < properties.length; i++) {
-            PropertyDescriptor propertyDescriptor = properties[i];
-            props.put(propertyDescriptor.getDisplayName(), 
propertyDescriptor.getReadMethod().invoke(bean));
-        }
+            throws JSONException {
+       Map<String, Object> props = new TreeMap<String, Object>();
+       try{  
+               PropertyDescriptor[] properties = 
Introspector.getBeanInfo(bean.getClass(), Object.class)
+                       .getPropertyDescriptors();
+               for (int i = 0; i < properties.length; i++) {
+                   PropertyDescriptor propertyDescriptor = properties[i];
+                   props.put(propertyDescriptor.getDisplayName(), 
propertyDescriptor.getReadMethod().invoke(bean));
+               }
+       }catch(IntrospectionException | InvocationTargetException | 
IllegalAccessException e){
+               throw new JSONException(e);
+       }
         return props;
     }
 

Reply via email to