Skip to content

Instantly share code, notes, and snippets.

@logbasex
Last active May 13, 2020 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logbasex/9a71f43fdeed021698fa17c680659ac4 to your computer and use it in GitHub Desktop.
Save logbasex/9a71f43fdeed021698fa17c680659ac4 to your computer and use it in GitHub Desktop.
import static java.util.Objects.*;
public static String[] getNullProperties(Object source) {
final BeanWrapper wrappedSource = new BeanWrapperImpl(source);
return Stream.of(wrappedSource.getPropertyDescriptors()).map(FeatureDescriptor::getName)
.filter(propertyName -> isNull(wrappedSource.getPropertyValue(propertyName))).toArray(String[]::new);
}
//copy propreties that ignore null field in the request
BeanUtils.copyProperties(request, object, getNullProperties(request));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment