- 普通的
public static Map<Object, Object> parseObjectToMap(Object o){ HashMap<Object, Object> resMap = Maps.newHashMap(); BeanMap beanMap = BeanMap.create(o); for (Object key : beanMap.keySet()) { resMap.put(key, beanMap.get(key)); } return resMap; }
- 带范型的
public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key.toString(), beanMap.get(key)); } } return map; }