package com.cmbchina.cc.mc.apcms.infrastructure.util;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.BeanInstantiationException;
import java.util.Map;
import java.util.Set;
/**
* description: add a description
*
* @author wang
* @version 1.0.0
* @date 2022/04/06 20:20:59
*/
public class BeanTools {
public static <T> T convertToNull(Class<T> clazz,Object object) throws BeanInstantiationException {
Map<String, Object> map = JSON.parseObject(JSON.toJSONString(object));
Set<String> set = map.keySet();
for (String key : set) {
Object values = map.get(key);
if (values instanceof String) {
values = ((String) values).trim();
if (values.equals("")) {
values = null;
}
}
map.put(key, values);
}
return JSON.parseObject(JSON.toJSONString(map), clazz);
}
}
实体类空串转换null工具类
于 2022-06-13 09:10:37 首次发布