#1379 - Proper type resolution for CollectionModel post-processing.
CollectionModelProcessorWrapper erroneously returned a raw type in case a CollectionModel type assignment check failed which rendered the element type verification to always match as it's effectively compared against Object. We're now returning null to rather proceed with the next candidate type.
This commit is contained in:
@@ -429,6 +429,7 @@ public class RepresentationModelProcessorInvoker {
|
||||
* @param superType must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
private static ResolvableType getSuperType(ResolvableType source, Class<?> superType) {
|
||||
|
||||
Class<?> rawType = source.getRawClass();
|
||||
@@ -449,7 +450,7 @@ public class RepresentationModelProcessorInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
return ResolvableType.forClass(superType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
* Unit tests for {@link RepresentationModelProcessorInvoker}.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @author Karina Pleskach
|
||||
*/
|
||||
public class RepresentationModelProcessorInvokerUnitTests {
|
||||
|
||||
@@ -54,6 +55,20 @@ public class RepresentationModelProcessorInvokerUnitTests {
|
||||
assertThat(processor.invoked).isFalse();
|
||||
}
|
||||
|
||||
@Test // #1379
|
||||
void doesNotInvokeProcessorForNonAssignableNestedEntityOnSpecializedCollectionModel() {
|
||||
|
||||
FirstEntityProcessor firstProcessor = new FirstEntityProcessor();
|
||||
|
||||
RepresentationModelProcessorInvoker invoker = new RepresentationModelProcessorInvoker(
|
||||
singletonList(firstProcessor));
|
||||
|
||||
EntityModel<SecondEntity> entityModel = EntityModel.of(new SecondEntity());
|
||||
invoker.invokeProcessorsFor(new MyCollectionModelInheritor<>(singletonList(entityModel)));
|
||||
|
||||
assertThat(firstProcessor.invoked).isFalse();
|
||||
}
|
||||
|
||||
// #1280
|
||||
|
||||
static class GenericPostProcessor<T extends GenericModel<T>> implements RepresentationModelProcessor<T> {
|
||||
@@ -82,4 +97,10 @@ public class RepresentationModelProcessorInvokerUnitTests {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
static class MyCollectionModelInheritor<T> extends CollectionModel<T> {
|
||||
public MyCollectionModelInheritor(Iterable<T> content) {
|
||||
super(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user