org.sdn.api.utils.EntityUtils Maven / Gradle / Ivy
package org.sdn.api.utils;
import org.sdn.api.DefaultOpenClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.lang.reflect.Field;
/**
* Created by softw on 2018/12/2.
*/
public class EntityUtils {
private static Logger logger = LoggerFactory.getLogger(EntityUtils.class);
/**
* 实体类转Map
* @param object
* @return
*/
public static Map entityToMap(Object object) {
Map map = new HashMap();
for (Field field : object.getClass().getDeclaredFields()){
try {
boolean flag = field.isAccessible();
field.setAccessible(true);
Object o = field.get(object);
map.put(field.getName(), o);
field.setAccessible(flag);
} catch (Exception e) {
logger.info(" EntityUtils entityToMap() Exception error={}",e.getMessage());
}
}
return map;
}
}