对象转换为value 字符串Map
/**
* @Email: CloverAn@aliyun.com
* 对象转换为value 字符串Map
* @param object
* @return
*/
public static Map<String, String> convertBeanToMap(Object object) {
if (object == null) {
return null;
}
Map<String, String> map = new HashMap<>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName();
if (!key.equals("class")) {
Method getter = property.getReadMethod();
Object value = getter.invoke(object);
if (value instanceof Date) {
map.put(key,String.valueOf(((Date) value).getTime()));
}else{
map.put(key, String.valueOf(value));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}