Skip to content

Commit 36ddb28

Browse files
committed
#1280 - Fix in invocation of generic RepresentationModelProcessor.
1 parent 6b8e30e commit 36ddb28

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

src/main/java/org/springframework/hateoas/server/mvc/RepresentationModelProcessorInvoker.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,7 @@ private static boolean isRawTypeAssignable(@Nullable ResolvableType left, @Nulla
171171
}
172172

173173
private static Class<?> getRawType(@Nullable ResolvableType type) {
174-
175-
if (type == null) {
176-
return Object.class;
177-
}
178-
179-
Class<?> rawType = type.getRawClass();
180-
return rawType == null ? Object.class : rawType;
174+
return type == null ? Object.class : type.resolve(Object.class);
181175
}
182176

183177
/**
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.hateoas.server.mvc;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import java.util.Collections;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.springframework.hateoas.CollectionModel;
24+
import org.springframework.hateoas.RepresentationModel;
25+
import org.springframework.hateoas.server.RepresentationModelProcessor;
26+
27+
/**
28+
* Unit tests for {@link RepresentationModelProcessorInvoker}.
29+
*
30+
* @author Oliver Drotbohm
31+
*/
32+
public class RepresentationModelProcessorInvokerUnitTests {
33+
34+
@Test // #1280
35+
void doesNotInvokeGenericProcessorForCollectionModel() {
36+
37+
RepresentationModelProcessorInvoker invoker = new RepresentationModelProcessorInvoker(
38+
Collections.singletonList(new GenericPostProcessor<>()));
39+
40+
assertThatCode(() -> invoker.invokeProcessorsFor(CollectionModel.empty())) //
41+
.doesNotThrowAnyException();
42+
}
43+
44+
// #1280
45+
46+
static class GenericPostProcessor<T extends GenericModel<T>> implements RepresentationModelProcessor<T> {
47+
48+
@Override
49+
public T process(T model) {
50+
return model;
51+
}
52+
}
53+
54+
static class GenericModel<T extends RepresentationModel<T>> extends RepresentationModel<T> {}
55+
}

0 commit comments

Comments
 (0)