Remove use of Optional in SyncHandlerMethodArgumentResolver
... and a couple more protected methods in WebFlux Issue: SPR-15718
This commit is contained in:
@@ -23,7 +23,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
@@ -91,19 +90,21 @@ public abstract class Jackson2CodecSupport {
|
||||
}
|
||||
|
||||
protected Map<String, Object> getHints(ResolvableType resolvableType) {
|
||||
return getParameter(resolvableType)
|
||||
.flatMap(parameter -> Optional.ofNullable(getAnnotation(parameter, JsonView.class))
|
||||
.map(annotation -> {
|
||||
Class<?>[] classes = annotation.value();
|
||||
Assert.isTrue(classes.length == 1, JSON_VIEW_HINT_ERROR + parameter);
|
||||
return Collections.<String, Object>singletonMap(JSON_VIEW_HINT, classes[0]);
|
||||
}))
|
||||
.orElse(Collections.emptyMap());
|
||||
MethodParameter param = getParameter(resolvableType);
|
||||
if (param != null) {
|
||||
JsonView annotation = getAnnotation(param, JsonView.class);
|
||||
if (annotation != null) {
|
||||
Class<?>[] classes = annotation.value();
|
||||
Assert.isTrue(classes.length == 1, JSON_VIEW_HINT_ERROR + param);
|
||||
return Collections.singletonMap(JSON_VIEW_HINT, classes[0]);
|
||||
}
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
protected Optional<MethodParameter> getParameter(ResolvableType type) {
|
||||
return Optional.ofNullable(type.getSource() instanceof MethodParameter ?
|
||||
(MethodParameter) type.getSource() : null);
|
||||
@Nullable
|
||||
protected MethodParameter getParameter(ResolvableType type) {
|
||||
return type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -109,7 +109,8 @@ public class Jackson2JsonDecoder extends Jackson2CodecSupport implements HttpMes
|
||||
Assert.notNull(tokens, "'tokens' must not be null");
|
||||
Assert.notNull(elementType, "'elementType' must not be null");
|
||||
|
||||
Class<?> contextClass = getParameter(elementType).map(MethodParameter::getContainingClass).orElse(null);
|
||||
MethodParameter param = getParameter(elementType);
|
||||
Class<?> contextClass = (param != null ? param.getContainingClass() : null);
|
||||
JavaType javaType = getJavaType(elementType.getType(), contextClass);
|
||||
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user