use of org.springframework.cglib.beans.BeanMap in project slate by shepherdviolet.
the class MapToBeanConverterImpl method convert0.
/**
* Convert
*/
private void convert0(Map<String, Object> fromMap, Object toBean, ConversionPath conversionPath) {
if (fromMap == null || fromMap.size() <= 0 || toBean == null) {
return;
}
// Create BeanMap of toBean, and get propertyInfos of toBean
BeanMap toBeanMap;
Map<String, BeanInfoUtils.PropertyInfo> toBeanPropertyInfos;
try {
toBeanMap = BeanMap.create(toBean);
toBeanPropertyInfos = BeanInfoUtils.getPropertyInfos(toBean.getClass());
} catch (Throwable e) {
throwConversionException("MapXBean: Error while mapping Map to " + toBean.getClass().getName() + ", map data:" + fromMap, e, conversionPath);
return;
}
// Handle all properties in toBean
for (Object keyObj : toBeanMap.keySet()) {
// KV
String key = String.valueOf(keyObj);
Object value = fromMap.get(convertMapKey(key));
if (propertyUpperCamelCase) {
if (value == null) {
// Get by lowerCase
value = fromMap.get(key);
if (value == null) {
continue;
}
}
} else {
if (value == null) {
continue;
}
}
// Property info
BeanInfoUtils.PropertyInfo toBeanPropertyInfo = toBeanPropertyInfos.get(key);
// Check write method
if (inspectBeanStrictly) {
if (toBeanPropertyInfo.getReadMethod() == null || toBeanPropertyInfo.getWriteMethod() == null) {
continue;
}
} else {
if (toBeanPropertyInfo.getWriteMethod() == null) {
continue;
}
}
// From this type
Class<?> valueClass = value.getClass();
// To this type
Class<?> expectClass = toBeanMap.getPropertyType(key);
Type expectType = toBeanPropertyInfo.getPropertyType();
// Create sub ConversionPath for element
ConversionPath subConversionPath = new ConversionPath(key, valueClass, expectClass, expectType, conversionPath);
// Convert property
Object convertedValue;
try {
convertedValue = propertyConverter.convert(value, valueClass, expectClass, expectType, subConversionPath);
} catch (Throwable e) {
throwConversionException("MapXBean: Error while mapping Map to " + toBean.getClass().getName() + ", property \"" + key + "\" mapping failed, map data:" + fromMap, e, subConversionPath);
continue;
}
// Skip if null
if (convertedValue == null) {
continue;
}
// Put into bean
try {
toBeanMap.put(keyObj, convertedValue);
} catch (Throwable e) {
throwConversionException("MapXBean: Error while mapping Map to " + toBean.getClass().getName() + ", putting \"" + key + "\" failed, map data:" + fromMap, e, subConversionPath);
}
}
}
use of org.springframework.cglib.beans.BeanMap in project kykms by mahonelau.
the class RedisServiceImpl method getMapForReport.
/**
* 查询redis信息for报表
* @param type 1redis key数量 2 占用内存 3redis信息
* @return
* @throws RedisConnectException
*/
@Override
public Map<String, JSONArray> getMapForReport(String type) throws RedisConnectException {
Map<String, JSONArray> mapJson = new HashMap<String, JSONArray>();
JSONArray json = new JSONArray();
if ("3".equals(type)) {
List<RedisInfo> redisInfo = getRedisInfo();
for (RedisInfo info : redisInfo) {
Map<String, Object> map = Maps.newHashMap();
BeanMap beanMap = BeanMap.create(info);
for (Object key : beanMap.keySet()) {
map.put(key + "", beanMap.get(key));
}
json.add(map);
}
mapJson.put("data", json);
return mapJson;
}
for (int i = 0; i < 5; i++) {
JSONObject jo = new JSONObject();
Map<String, Object> map;
if ("1".equals(type)) {
map = getKeysSize();
jo.put("value", map.get("dbSize"));
} else {
map = getMemoryInfo();
Integer used_memory = Integer.valueOf(map.get("used_memory").toString());
jo.put("value", used_memory / 1000);
}
String create_time = DateUtil.formatTime(DateUtil.date((Long) map.get("create_time") - (4 - i) * 1000));
jo.put("name", create_time);
json.add(jo);
}
mapJson.put("data", json);
return mapJson;
}
use of org.springframework.cglib.beans.BeanMap in project buessionframework by buession.
the class BeanUtils method toMap.
/**
* 将 bean 对象转换成 {@link Map} 对象
*
* @param bean
* Bean 对象
*
* @return Map
*/
@SuppressWarnings("rawtypes")
public static Map<String, Object> toMap(final Object bean) {
Assert.isNull(bean, "No source bean specified.");
if (bean instanceof Map) {
final Map<?, ?> beanMap = (Map<?, ?>) bean;
final Map<String, Object> result = new HashMap<>(beanMap.size());
beanMap.forEach((key, value) -> {
if (key != null) {
result.put(key.toString(), value);
}
});
return result;
} else {
BeanMap beanMap = BeanMap.create(bean);
return new HashMap<>(beanMap);
}
}
use of org.springframework.cglib.beans.BeanMap in project spring-boot-starter-jdbc-helper by nyvi.
the class BeanMapUtils method beanToMap.
/**
* bean转为Map
* @param bean 实体bean
* @param ignore 是否忽略值为空的字段
* @param <T> 泛型
* @return map对象
*/
public static final <T> Map<String, Object> beanToMap(T bean, boolean ignore) {
if (Objects.isNull(bean)) {
return new HashMap<>(0);
}
BeanMap beanMap = BeanMap.create(bean);
Map<String, Object> map = Maps.newHashMap(beanMap.size());
for (Object key : beanMap.keySet()) {
Object value = beanMap.get(key);
if (ignore && Objects.isNull(value)) {
continue;
}
map.put(key.toString(), value);
}
return map;
}
use of org.springframework.cglib.beans.BeanMap in project spring-boot-starter-jdbc-helper by nyvi.
the class BeanMapUtils method mapToBean.
/**
* Map转Bean
* @param map map对象
* @param bean 实体
* @param <T> 泛型
* @return bean对象
*/
public static <T> T mapToBean(Map<String, Object> map, T bean) {
BeanMap beanMap = BeanMap.create(bean);
beanMap.putAll(map);
return bean;
}
Aggregations