DATACMNS-1296 - PersistentPropertyPathAccessor now properly handles intermediate nulls when setting values.
We now use a dedicated GetOptions instance for the lookup of the parent path in case SetOptions is defined to skip nulls so that the lookup does not fail if the parent path contains a null value.
This commit is contained in:
@@ -24,10 +24,10 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.data.mapping.AccessOptions;
|
||||
import org.springframework.data.mapping.AccessOptions.GetOptions;
|
||||
import org.springframework.data.mapping.AccessOptions.GetOptions.GetNulls;
|
||||
import org.springframework.data.mapping.AccessOptions.SetOptions;
|
||||
import org.springframework.data.mapping.AccessOptions.SetOptions.SetNulls;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
@@ -51,6 +51,7 @@ import org.springframework.util.Assert;
|
||||
class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathAccessor<T> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SimplePersistentPropertyPathAccessor.class);
|
||||
private static final GetOptions DEFAULT_GET_OPTIONS = AccessOptions.defaultGetOptions();
|
||||
|
||||
private final PersistentPropertyAccessor<T> delegate;
|
||||
|
||||
@@ -84,7 +85,7 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path) {
|
||||
return getProperty(path, AccessOptions.defaultGetOptions());
|
||||
return getProperty(path, DEFAULT_GET_OPTIONS);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -154,7 +155,11 @@ class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathA
|
||||
return;
|
||||
}
|
||||
|
||||
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath);
|
||||
GetOptions lookupOptions = options.getNullHandling() != REJECT
|
||||
? DEFAULT_GET_OPTIONS.withNullValues(GetNulls.EARLY_RETURN)
|
||||
: DEFAULT_GET_OPTIONS;
|
||||
|
||||
Object parent = parentPath.isEmpty() ? getBean() : getProperty(parentPath, lookupOptions);
|
||||
|
||||
if (parent == null) {
|
||||
handleNull(path, options.getNullHandling());
|
||||
|
||||
Reference in New Issue
Block a user