@Test public void testBeanToMap() throws Exception { Bean1 b = new Bean1(); b.setOne("1"); b.setTwo(true); Map<String, Object> map = BeanUtils.beanToMap(b); assertNotNull(map); assertEquals(3, map.size()); assertEquals("1", map.get("one")); assertTrue((Boolean) map.get("two")); assertNotNull(map.get("three")); }
public static Map<String, Object> beanToMap(Object bean) throws InvocationTargetException { if (bean == null) { return null; } Map<String, Object> result = new HashMap<String, Object>(); Collection<Method> getters = getGetters(bean); for (Method method : getters) { try { result.put(toAttributeName(method), method.invoke(bean)); } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } } return result; }
BeanUtils { public static Map<String, Object> beanToMap(Object bean) throws InvocationTargetException { if (bean == null) { return null; } Map<String, Object> result = new HashMap<String, Object>(); Collection<Method> getters = getGetters(bean); for (Method method : getters) { try { result.put(toAttributeName(method), method.invoke(bean)); } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } } return result; } }
BeanUtils { public static Map<String, Object> beanToMap(Object bean) throws InvocationTargetException { if (bean == null) { return null; } Map<String, Object> result = new HashMap<String, Object>(); Collection<Method> getters = getGetters(bean); for (Method method : getters) { try { result.put(toAttributeName(method), method.invoke(bean)); } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } } return result; }  }
BeanUtils { public static Map<String, Object> beanToMap(Object bean) throws InvocationTargetException { if (bean == null) { return null; } Map<String, Object> result = new HashMap<String, Object>(); Collection<Method> getters = getGetters(bean); for (Method method : getters) { try { result.put(toAttributeName(method), method.invoke(bean)); } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } } return result; }  static Map<String, Object> beanToMap(Object bean); static void mapToBean(Object bean, Map<String, Object> data, boolean ignoreNotExistingSetter); static Collection<Method> getGetters(Object bean); static Collection<Method> getSetters(Object bean); static String toAttributeName(Method m); static Method getSetter(Object bean, String attributeName); }
BeanUtils { public static Map<String, Object> beanToMap(Object bean) throws InvocationTargetException { if (bean == null) { return null; } Map<String, Object> result = new HashMap<String, Object>(); Collection<Method> getters = getGetters(bean); for (Method method : getters) { try { result.put(toAttributeName(method), method.invoke(bean)); } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } } return result; }  static Map<String, Object> beanToMap(Object bean); static void mapToBean(Object bean, Map<String, Object> data, boolean ignoreNotExistingSetter); static Collection<Method> getGetters(Object bean); static Collection<Method> getSetters(Object bean); static String toAttributeName(Method m); static Method getSetter(Object bean, String attributeName);  }