1. Copy the object

  2. List object Copy

  3. The Map copy

  4. Json to turn the Map

  5. Gets an empty property of the object

import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.BeanUtils; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @program: XXX * @description: Bean conversion tool * @author: 52Hz * @create: 2021-10-21 16:31 **/ public class BeanUtil {/** ** @param source * @param target */ public static void copyProperties(Object source, Object target) { if (source == null) { return; } BeanUtils.copyProperties(source, target); Public static <T, E> List copyList(List<T> List, List<T> List) Class<E> clazz) { if (CollectionUtils.isEmpty(list)) { return new ArrayList(); } return JSON.parseArray(JSON.toJSONString(list), clazz); } public static MAP <String, public static MAP <String, Object> copyMap(Map map) { if (CollectionUtils.isEmpty(map)) { return new HashMap<>(); } return JSON.parseObject(JSON.toJSONString(map)); } @param json * @return */ public static Map<String Object> jsonToMap(String json) { try { ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.readValue(json, Map.class); } catch (Exception ex) { ex.printStackTrace(); } return null; Private static String[] getNullPropertyNames(Object source) {private static String[] getNullPropertyNames(Object source) { BeanWrapper src = new BeanWrapperImpl(source); PropertyDescriptor[] pds = src.getPropertyDescriptors(); Set<String> emptyNames = (Set) Arrays.stream(pds).filter((pd) -> { return src.getPropertyValue(pd.getName()) == null; }).map(FeatureDescriptor::getName).distinct().collect(Collectors.toSet()); String[] result = new String[emptyNames.size()]; return (String[])emptyNames.toArray(result); }}Copy the code