diff --git a/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java b/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java index 013522815..f09c347a4 100644 --- a/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java +++ b/src/main/java/org/springframework/data/projection/ProjectingMethodInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,7 +137,7 @@ class ProjectingMethodInterceptor implements MethodInterceptor { } private Object getProjection(Object result, Class returnType) { - return ClassUtils.isAssignable(returnType, result.getClass()) ? result + return result == null || ClassUtils.isAssignable(returnType, result.getClass()) ? result : factory.createProjection(returnType, result); } diff --git a/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java b/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java index 5677fc189..2c683c8ca 100644 --- a/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import static org.junit.Assert.*; import java.beans.PropertyDescriptor; import java.lang.reflect.Proxy; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -159,7 +160,7 @@ public class ProxyProjectionFactoryUnitTests { ProjectionInformation projectionInformation = factory.getProjectionInformation(CustomerExcerpt.class); List result = projectionInformation.getInputProperties(); - assertThat(result, hasSize(5)); + assertThat(result, hasSize(6)); } /** @@ -247,6 +248,22 @@ public class ProxyProjectionFactoryUnitTests { assertThat(information.isClosed(), is(true)); } + /** + * @see DATACMNS-829 + */ + @Test + public void projectsMapOfStringToObjectCorrectly() { + + Customer customer = new Customer(); + customer.data = Collections.singletonMap("key", null); + + Map data = factory.createProjection(CustomerExcerpt.class, customer).getData(); + + assertThat(data, is(notNullValue())); + assertThat(data.containsKey("key"), is(true)); + assertThat(data.get("key"), is(nullValue())); + } + static class Customer { public Long id; @@ -254,6 +271,7 @@ public class ProxyProjectionFactoryUnitTests { public Address address; public byte[] picture; public Address[] shippingAddresses; + public Map data; } static class Address { @@ -272,6 +290,8 @@ public class ProxyProjectionFactoryUnitTests { AddressExcerpt[] getShippingAddresses(); byte[] getPicture(); + + Map getData(); } interface AddressExcerpt {