public static Map<String,Object> tranceClassToMap(Object bean,boolean hasNull){
String jsonString;
if(hasNull){
jsonString = JSONObject.toJSONString(bean, SerializerFeature.WriteMapNullValue);
}else{
jsonString = JSONObject.toJSONString(bean);
}
Map map = JSONObject.parseObject(jsonString, Map.class);
if(map == null){
map = new HashMap();
}
return map;
}
public static Map<String, Object> objectToMap(Object obj) throws Exception {
if(obj == null){
return null;
}
Map<String, Object> map = new HashMap<String, Object>();
Field[] declaredFields = obj.getClass().getDeclaredFields();
for (Field field : declaredFields) {
field.setAccessible(true);
if(field.get(obj)!=null){
map.put(field.getName(), field.get(obj));
}else if(field.getType().getName().equals("java.util.Date")){
map.put(field.getName(), field.get(obj));
}
}
return map;
}