use of io.seata.common.exception.NotSupportYetException in project seata by seata.
the class BeanUtils method objectToMap.
/**
* object to map
*
* @param object the object
* @return the map
*/
public static Map<String, String> objectToMap(Object object) {
if (object == null) {
return null;
}
Map<String, String> map = new HashMap<>(16);
Field[] fields = object.getClass().getDeclaredFields();
try {
for (Field field : fields) {
boolean accessible = field.isAccessible();
field.setAccessible(true);
if (field.getType() == Date.class) {
Date date = (Date) field.get(object);
if (date != null) {
map.put(field.getName(), String.valueOf(date.getTime()));
}
} else {
map.put(field.getName(), field.get(object) == null ? "" : field.get(object).toString());
}
field.setAccessible(accessible);
}
} catch (IllegalAccessException e) {
throw new NotSupportYetException("object " + object.getClass().toString() + " to map failed:" + e.getMessage());
}
return map;
}
Aggregations