DATAREST-385 - Projection definition configurations are now detected for super types.

Projections defined for a parent type are now also available for sub-types.
This commit is contained in:
Oliver Gierke
2014-10-15 11:56:39 +02:00
parent 73526e9158
commit 32bda65bcf
2 changed files with 25 additions and 3 deletions

View File

@@ -124,7 +124,7 @@ public class ProjectionDefinitionConfiguration implements ProjectionDefinitions
*/
@Override
public Class<?> getProjectionType(Class<?> sourceType, String name) {
return projectionDefinitions.get(new ProjectionDefinitionKey(sourceType, name));
return getProjectionsFor(sourceType).get(name);
}
/*
@@ -135,7 +135,7 @@ public class ProjectionDefinitionConfiguration implements ProjectionDefinitions
public boolean hasProjectionFor(Class<?> sourceType) {
for (ProjectionDefinitionKey key : projectionDefinitions.keySet()) {
if (key.sourceType.equals(sourceType)) {
if (key.sourceType.isAssignableFrom(sourceType)) {
return true;
}
}
@@ -156,7 +156,7 @@ public class ProjectionDefinitionConfiguration implements ProjectionDefinitions
Map<String, Class<?>> result = new HashMap<String, Class<?>>();
for (Entry<ProjectionDefinitionKey, Class<?>> entry : projectionDefinitions.entrySet()) {
if (entry.getKey().sourceType.equals(sourceType)) {
if (entry.getKey().sourceType.isAssignableFrom(sourceType)) {
result.put(entry.getKey().name, entry.getValue());
}
}

View File

@@ -135,6 +135,21 @@ public class ProjectionDefinitionConfigurationUnitTests {
assertThat(objectOtherNameKey, is(not(objectNameKey)));
}
/**
* @see DATAREST-385
*/
@Test
public void returnsProjectionForParentClass() {
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
configuration.addProjection(ParentProjection.class);
assertThat(configuration.hasProjectionFor(Child.class), is(true));
assertThat(configuration.getProjectionsFor(Child.class).values(), hasItem(ParentProjection.class));
assertThat(configuration.getProjectionType(Child.class, "parentProjection"),
is(typeCompatibleWith(ParentProjection.class)));
}
@Projection(name = "name", types = Integer.class)
interface SampleProjection {
@@ -144,4 +159,11 @@ public class ProjectionDefinitionConfigurationUnitTests {
interface Default {
}
class Parent {}
class Child extends Parent {}
@Projection(types = Parent.class)
interface ParentProjection {}
}