diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandler.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandler.java index 50a6ec29a..210d4912e 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandler.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandler.java @@ -439,7 +439,13 @@ public class ResourceProcessorHandlerMethodReturnValueHandler implements Handler Class resourcesType = resources.getClass(); - TypeInformation resourceTypeInformation = target.getSuperTypeInformation(resourcesType).getComponentType(); + TypeInformation superTypeInformation = target.getSuperTypeInformation(resourcesType); + + if (superTypeInformation == null) { + return false; + } + + TypeInformation resourceTypeInformation = superTypeInformation.getComponentType(); return ResourceProcessorWrapper.isValueTypeMatch((Resource) element, resourceTypeInformation); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandlerUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandlerUnitTests.java index 8a8a4a21e..d60602d17 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandlerUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceProcessorHandlerMethodReturnValueHandlerUnitTests.java @@ -241,6 +241,20 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests { assertThat(projectionProcessor.invoked, is(true)); } + /** + * @see DATAREST-331 + */ + @Test + public void doesNotMatchOnNonMatchingResourcesTypes() throws Exception { + + Resource resource = new Resource(new Object()); + PagedResources> pagedResources = new PagedResources>( + Collections.singleton(resource), new PageMetadata(1, 0, 10)); + + TypeInformation type = ClassTypeInformation.from(RepositoryLinksResource.class); + assertThat(ResourcesProcessorWrapper.isValueTypeMatch(pagedResources, type), is(false)); + } + // Helpers ---------------------------------------------------------// private void invokeReturnValueHandler(String method, final Matcher matcher, Object returnValue) throws Exception { final MethodParameter methodParam = METHOD_PARAMS.get(method);