Repository: wicket Updated Branches: refs/heads/wicket-6.x 4b66ccd45 -> c75fd77ad
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/c75fd77a Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c75fd77a Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c75fd77a Branch: refs/heads/wicket-6.x Commit: c75fd77adf6d65a1ba3d6aed9b056eb87f445996 Parents: 4b66ccd Author: Tobias Soloschenko <[email protected]> Authored: Sun Jan 15 14:44:14 2017 +0100 Committer: Tobias Soloschenko <[email protected]> Committed: Sun Jan 15 14:47:31 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/c75fd77a/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 2cf60ee..08b2bc0 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 bean 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; }
