diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentProperty.java b/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentProperty.java index 0e0d9bd13..47f573e4b 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentProperty.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentProperty.java @@ -16,6 +16,7 @@ package org.springframework.data.neo4j.core.mapping; import java.lang.reflect.Field; +import java.util.Collections; import java.util.Optional; import org.springframework.data.annotation.ReadOnlyProperty; @@ -209,7 +210,13 @@ final class DefaultNeo4jPersistentProperty extends AnnotationBasedPersistentProp @Override public boolean isEntity() { - return super.isEntity() && !isWritableProperty.get(); + return super.isEntity() && !isWritableProperty.get() && !this.isAnnotationPresent(ConvertWith.class); + } + + @Override + public Iterable> getPersistentEntityTypeInformation() { + return this.isAnnotationPresent(ConvertWith.class) ? Collections.emptyList() + : super.getPersistentEntityTypeInformation(); } @Override @@ -219,7 +226,7 @@ final class DefaultNeo4jPersistentProperty extends AnnotationBasedPersistentProp @Override public Neo4jPersistentPropertyConverter getOptionalConverter() { - return customConversion.getOptional() + return isEntity() ? null : customConversion.getOptional() .map(Neo4jPersistentPropertyConverter.class::cast) .orElse(null); } diff --git a/src/test/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntityTest.java b/src/test/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntityTest.java index 1bf8bd489..37276b063 100644 --- a/src/test/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntityTest.java +++ b/src/test/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntityTest.java @@ -34,6 +34,7 @@ import org.springframework.data.annotation.ReadOnlyProperty; import org.springframework.data.annotation.Transient; import org.springframework.data.mapping.AssociationHandler; import org.springframework.data.mapping.MappingException; +import org.springframework.data.neo4j.core.convert.ConvertWith; import org.springframework.data.neo4j.core.schema.DynamicLabels; import org.springframework.data.neo4j.core.schema.GeneratedValue; import org.springframework.data.neo4j.core.schema.Id; @@ -57,6 +58,16 @@ class DefaultNeo4jPersistentEntityTest { neo4jMappingContext.getPersistentEntity(CorrectEntity2.class); } + @Test + void skipsEntityTypeDetectionForConvertedProperties() { + + Neo4jPersistentEntity entity = new Neo4jMappingContext().getRequiredPersistentEntity(WithConvertedProperty.class); + Neo4jPersistentProperty property = entity.getRequiredPersistentProperty("converted"); + + assertThat(property.isEntity()).isFalse(); + assertThat(property.getPersistentEntityTypeInformation()).isEmpty(); + } + @Nested class ReadOnlyProperties { @@ -730,4 +741,14 @@ class DefaultNeo4jPersistentEntityTest { @Property(readOnly = false) private String writableProperty; } + + static class WithConvertedProperty { + + @ConvertWith + IWillBeConverted converted; + } + + static class IWillBeConverted { + + } }