object与map相互转换

public class DomainTransUtils {

    public static<T>  T parseMap2Object(Map<String,Object> paramMap,Class<T> clazz){
        return JSONObject.parseObject(JSONObject.toJSONString(paramMap),clazz);
    }

    public static Map<String, Object> objectToMap(Object obj) {
        if (obj == null) {
            return null;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            Field[] declaredFields = obj.getClass().getDeclaredFields();
            for (Field field : declaredFields) {
                field.setAccessible(true);
                map.put(field.getName(), field.get(obj));
            }
        } catch (Exception e) {

        }
        return map;
    }
}

 

posted @ 2020-03-20 20:49  忧伤还是快乐EL  阅读(705)  评论(0编辑  收藏  举报