diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMapping.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMapping.java index a0249ab1e..435b110a5 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMapping.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMapping.java @@ -91,7 +91,10 @@ class PersistentPropertyResourceMapping implements PropertyAwareResourceMapping } ResourceMapping typeMapping = mappings.getMetadataFor(property.getActualType()); - return !typeMapping.isExported() ? false : annotation.map(it -> it.exported()).orElse(true); + + return typeMapping != null && typeMapping.isExported() + ? annotation.map(it -> it.exported()).orElse(true) + : false; } /* diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java index 13f808d60..6ddfc5e96 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMappingUnitTests.java @@ -16,6 +16,7 @@ package org.springframework.data.rest.core.mapping; import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; import java.util.Arrays; import java.util.List; @@ -27,6 +28,8 @@ import org.springframework.data.annotation.Reference; import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity; import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty; import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; +import org.springframework.data.mapping.PersistentEntity; +import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.context.PersistentEntities; import org.springframework.data.rest.core.Path; import org.springframework.data.rest.core.annotation.Description; @@ -98,6 +101,20 @@ public class PersistentPropertyResourceMappingUnitTests { assertThat(description.getMessage()).isEqualTo("Some description"); } + @Test // #1994 + public void doesNotConsiderPropertyExportedIfTargetTypeIsNotMapped() { + + PersistentEntity entity = mappingContext.getRequiredPersistentEntity(Entity.class); + PersistentProperty property = entity.getRequiredPersistentProperty("third"); + + ResourceMappings mappings = mock(ResourceMappings.class); + when(mappings.getMetadataFor(property.getType())).thenReturn(null); + + ResourceMapping mapping = new PersistentPropertyResourceMapping(property, mappings); + + assertThat(mapping.isExported()).isFalse(); + } + private ResourceMapping getPropertyMappingFor(Class entity, String propertyName) { KeyValuePersistentEntity persistentEntity = mappingContext.getRequiredPersistentEntity(entity);