Skip to content

Commit a1f4566

Browse files
committed
Skip entity detection for converted properties.
DefaultNeo4jPersistentProperty.isEntity() and getPersistentEntityTypeInformation() now return that the property does not map to an entity if a converter is registered. Closes #2869
1 parent cb896af commit a1f4566

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.neo4j.core.mapping;
1717

1818
import java.lang.reflect.Field;
19+
import java.util.Collections;
1920
import java.util.Optional;
2021

2122
import org.springframework.data.annotation.ReadOnlyProperty;
@@ -209,7 +210,13 @@ public boolean isAssociation() {
209210

210211
@Override
211212
public boolean isEntity() {
212-
return super.isEntity() && !isWritableProperty.get();
213+
return super.isEntity() && !isWritableProperty.get() && !this.isAnnotationPresent(ConvertWith.class);
214+
}
215+
216+
@Override
217+
public Iterable<? extends TypeInformation<?>> getPersistentEntityTypeInformation() {
218+
return this.isAnnotationPresent(ConvertWith.class) ? Collections.emptyList()
219+
: super.getPersistentEntityTypeInformation();
213220
}
214221

215222
@Override
@@ -219,7 +226,7 @@ public boolean isEntityWithRelationshipProperties() {
219226

220227
@Override
221228
public Neo4jPersistentPropertyConverter<?> getOptionalConverter() {
222-
return customConversion.getOptional()
229+
return isEntity() ? null : customConversion.getOptional()
223230
.map(Neo4jPersistentPropertyConverter.class::cast)
224231
.orElse(null);
225232
}

src/test/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntityTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.data.annotation.Transient;
3535
import org.springframework.data.mapping.AssociationHandler;
3636
import org.springframework.data.mapping.MappingException;
37+
import org.springframework.data.neo4j.core.convert.ConvertWith;
3738
import org.springframework.data.neo4j.core.schema.DynamicLabels;
3839
import org.springframework.data.neo4j.core.schema.GeneratedValue;
3940
import org.springframework.data.neo4j.core.schema.Id;
@@ -57,6 +58,16 @@ void persistentEntityCreationWorksForCorrectEntity() {
5758
neo4jMappingContext.getPersistentEntity(CorrectEntity2.class);
5859
}
5960

61+
@Test
62+
void skipsEntityTypeDetectionForConvertedProperties() {
63+
64+
Neo4jPersistentEntity<?> entity = new Neo4jMappingContext().getRequiredPersistentEntity(WithConvertedProperty.class);
65+
Neo4jPersistentProperty property = entity.getRequiredPersistentProperty("converted");
66+
67+
assertThat(property.isEntity()).isFalse();
68+
assertThat(property.getPersistentEntityTypeInformation()).isEmpty();
69+
}
70+
6071
@Nested
6172
class ReadOnlyProperties {
6273

@@ -730,4 +741,14 @@ static class WithAnnotatedProperties {
730741
@Property(readOnly = false)
731742
private String writableProperty;
732743
}
744+
745+
static class WithConvertedProperty {
746+
747+
@ConvertWith
748+
IWillBeConverted converted;
749+
}
750+
751+
static class IWillBeConverted {
752+
753+
}
733754
}

0 commit comments

Comments
 (0)