Skip to content

Commit 32e7ada

Browse files
committed
GH-2395 - Respect null values for primitives in DTO projection conversion.
Closes #2395
1 parent faf849d commit 32e7ada

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/EntityFromDtoInstantiatingConverter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.data.mapping.SimplePropertyHandler;
2727
import org.springframework.data.mapping.model.ParameterValueProvider;
2828
import org.springframework.data.util.ClassTypeInformation;
29+
import org.springframework.data.util.ReflectionUtils;
2930
import org.springframework.lang.Nullable;
3031
import org.springframework.util.Assert;
3132

@@ -102,11 +103,17 @@ Object getPropertyValueFor(PersistentProperty<?> targetProperty, PersistentEntit
102103
PersistentPropertyAccessor<?> sourceAccessor) {
103104

104105
String targetPropertyName = targetProperty.getName();
106+
Class<?> targetPropertyType = targetProperty.getType();
105107
PersistentProperty<?> sourceProperty = sourceEntity.getPersistentProperty(targetPropertyName);
108+
Object propertyValue = null;
106109
if (sourceProperty != null) {
107-
return sourceAccessor.getProperty(sourceProperty);
110+
propertyValue = sourceAccessor.getProperty(sourceProperty);
108111
}
109112

110-
return null;
113+
if (propertyValue == null && targetPropertyType.isPrimitive()) {
114+
return ReflectionUtils.getPrimitiveDefault(targetPropertyType);
115+
}
116+
117+
return propertyValue;
111118
}
112119
}

src/test/java/org/springframework/data/neo4j/integration/shared/common/Person.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class Person {
3030
private String firstName;
3131
private String lastName;
3232

33+
private int primitiveValue; // never used but always null
34+
3335
@Relationship("LIVES_AT") private Address address;
3436

3537
/**

0 commit comments

Comments
 (0)