cn.foxtech.common.utils.bean.BeanMapUtils Maven / Gradle / Ivy
/* ----------------------------------------------------------------------------
* Copyright (c) Guangzhou Fox-Tech Co., Ltd. 2020-2024. All rights reserved.
* --------------------------------------------------------------------------- */
package cn.foxtech.common.utils.bean;
import org.springframework.cglib.beans.BeanMap;
import java.util.*;
/**
* BeanMap反射工具
*/
public class BeanMapUtils {
/**
* map转java对象
*
* @param map Map对象
* @param beanClass 待构造的对象类型
* @return 对象
* @throws Exception 转换异常
*/
public static Object mapToObject(Map map, Class> beanClass) throws Exception {
Object object = beanClass.newInstance();
BeanMap beanMap = BeanMap.create(object);
beanMap.putAll(map);
return object;
}
/**
* 将对象转换为Map
*
* @param obj 对象
* @return Map
*/
public static Map objectToMap(Object obj) {
Map map = new HashMap<>();
if (obj != null) {
BeanMap beanMap = BeanMap.create(obj);
for (Object key : beanMap.keySet()) {
map.put(key + "", beanMap.get(key));
}
}
return map;
}
/**
* 生成的Map后,剔除指定的key
*
* @param objectList 对象
* @param filterKeys 要剔除的Key
* @param 类型名
* @return map
*/
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy