How to ignore null values using springframework BeanUtils copyProperties?

后端 未结 6 1325
悲哀的现实
悲哀的现实 2020-12-01 00:09

I would like to know how to copy the properties from an Object Source to an Object Dest ignoring null values​​ using Spring Framework.

I actually use Apache beanutil

6条回答
  •  鱼传尺愫
    2020-12-01 01:07

    public static List getNullProperties(Object source) {
        final BeanWrapper wrappedSource = new BeanWrapperImpl(source);
        return Stream.of(wrappedSource.getPropertyDescriptors())
            .map(FeatureDescriptor::getName)
            .filter(propertyName -> Objects.isNull(wrappedSource.getPropertyValue(propertyName)))
            .collect(Collectors.toList());
    

提交回复
热议问题