DATACMNS-829 - Fixed handling of Map null values in ProxyProjectionFactory.

We now eagerly return null values in attempts to project Map values.
This commit is contained in:
Oliver Gierke
2016-03-14 15:46:40 +01:00
parent 71de300ab1
commit bea31ae5f0
2 changed files with 36 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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.
@@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -157,7 +158,7 @@ public class ProxyProjectionFactoryUnitTests {
List<String> result = factory.getInputProperties(CustomerExcerpt.class);
assertThat(result, hasSize(5));
assertThat(result, hasSize(6));
assertThat(result, hasItems("firstname", "address", "shippingAddresses", "picture"));
}
@@ -222,6 +223,34 @@ public class ProxyProjectionFactoryUnitTests {
assertThat(excerpt.getId(), is(customer.id.toString()));
}
/**
* @see DATACMNS-89
*/
@Test
public void exposesProjectionInformationCorrectly() {
ProjectionInformation information = factory.getProjectionInformation(CustomerExcerpt.class);
assertThat(information.getType(), is(typeCompatibleWith(CustomerExcerpt.class)));
assertThat(information.isClosed(), is(true));
}
/**
* @see DATACMNS-829
*/
@Test
public void projectsMapOfStringToObjectCorrectly() {
Customer customer = new Customer();
customer.data = Collections.singletonMap("key", null);
Map<String, Object> 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;
@@ -229,6 +258,7 @@ public class ProxyProjectionFactoryUnitTests {
public Address address;
public byte[] picture;
public Address[] shippingAddresses;
public Map<String, Object> data;
}
static class Address {
@@ -247,6 +277,8 @@ public class ProxyProjectionFactoryUnitTests {
AddressExcerpt[] getShippingAddresses();
byte[] getPicture();
Map<String, Object> getData();
}
interface AddressExcerpt {