diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptor.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptor.java index b2ac58fbb..712eddc42 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptor.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptor.java @@ -18,6 +18,7 @@ package org.springframework.data.rest.core.projection; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; /** * {@link MethodInterceptor} to delegate the invocation to a different {@link MethodInterceptor} but creating a @@ -60,6 +61,8 @@ class ProjectingMethodInterceptor implements MethodInterceptor { } Class returnType = invocation.getMethod().getReturnType(); - return returnType.isAssignableFrom(result.getClass()) ? result : factory.createProjection(result, returnType); + + return ClassUtils.isAssignable(returnType, result.getClass()) ? result : factory.createProjection(result, + returnType); } } diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptorUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptorUnitTests.java index a7a4a0468..7232938a4 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptorUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/projection/ProjectingMethodInterceptorUnitTests.java @@ -17,6 +17,7 @@ package org.springframework.data.rest.core.projection; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import org.aopalliance.intercept.MethodInterceptor; @@ -79,10 +80,27 @@ public class ProjectingMethodInterceptorUnitTests { assertThat(methodInterceptor.invoke(invocation), is(nullValue())); } + /** + * @see DATAREST-221 + */ + @Test + public void considersPrimitivesAsWrappers() throws Throwable { + + MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(factory, interceptor); + + when(invocation.getMethod()).thenReturn(Helper.class.getMethod("getPrimitive")); + when(interceptor.invoke(invocation)).thenReturn(1L); + + assertThat(methodInterceptor.invoke(invocation), is((Object) 1L)); + verify(factory, times(0)).createProjection(anyObject(), (Class) anyObject()); + } + interface Helper { Helper getHelper(); String getString(); + + long getPrimitive(); } }