diff --git a/src/main/java/org/springframework/hateoas/mvc/AnnotatedParametersParameterAccessor.java b/src/main/java/org/springframework/hateoas/mvc/AnnotatedParametersParameterAccessor.java index dd21f980..d4f7aeb3 100644 --- a/src/main/java/org/springframework/hateoas/mvc/AnnotatedParametersParameterAccessor.java +++ b/src/main/java/org/springframework/hateoas/mvc/AnnotatedParametersParameterAccessor.java @@ -139,12 +139,10 @@ class AnnotatedParametersParameterAccessor { Assert.notNull(parameter, "MethodParameter must not be null!"); - boolean isOptional = Java8Utils.isJava8Optional(parameter.getParameterType()); - this.parameter = parameter; this.value = value; this.attribute = attribute; - this.parameterTypeDescriptor = TypeDescriptor.nested(parameter, isOptional ? 1 : 0); + this.parameterTypeDescriptor = TypeDescriptor.nested(parameter, parameter.isOptional() ? 1 : 0); } /** diff --git a/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactory.java b/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactory.java index e21e0bb7..9afe3f04 100644 --- a/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactory.java +++ b/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactory.java @@ -45,6 +45,7 @@ import org.springframework.hateoas.core.MethodParameters; import org.springframework.hateoas.mvc.AnnotatedParametersParameterAccessor.BoundMethodParameter; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; +import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -299,7 +300,7 @@ public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory type) { - - Assert.notNull(type, "Type must not be null!"); - - return OPTIONAL_PRESENT && OptionalValueAccessor.isOptional(type); - } - - /** - * Returns whether the given source value is a JDK 8 {@link Optional}. - * - * @param source can be {@literal null}. - * @return - */ - static boolean isJava8Optional(Object source) { - return OPTIONAL_PRESENT && OptionalValueAccessor.isOptional(source); - } - - /** - * Unwraps the value contained in a JDK 8 {@link Optional} if the value is one. - * - * @param source can be {@literal null}. - * @return - */ - static Object unwrapJava8Optional(Object source) { - return OPTIONAL_PRESENT && isJava8Optional(source) ? OptionalValueAccessor.unwrapOptional(source) : source; - } - - private static class OptionalValueAccessor { - - static boolean isOptional(Class type) { - return Optional.class.isAssignableFrom(type); - } - - static boolean isOptional(Object source) { - return Optional.class.isInstance(source); - } - - static Object unwrapOptional(Object source) { - return ((Optional) source).orElse(null); - } - } -}