Change ServerRequest.attribute(String) to return Object

This commit changes `ServerRequest.attribute(String)`` to return
`Optional<Object>` instead of `Optional<T>`, where `T` was infered
from a type parameter.
This commit is contained in:
Arjen Poutsma 2017-07-11 11:24:29 +02:00
parent dfcc9af938
commit e11bb17aa6
6 changed files with 11 additions and 21 deletions

View File

@ -156,12 +156,6 @@ public class MockServerRequest implements ServerRequest {
return (Flux<S>) this.body;
}
@SuppressWarnings("unchecked")
@Override
public <S> Optional<S> attribute(String name) {
return Optional.ofNullable((S) this.attributes.get(name));
}
@Override
public Map<String, Object> attributes() {
return this.attributes;

View File

@ -145,11 +145,6 @@ class DefaultServerRequest implements ServerRequest {
return flux.onErrorMap(UnsupportedMediaTypeException.class, ERROR_MAPPER);
}
@Override
public <T> Optional<T> attribute(String name) {
return Optional.ofNullable(this.exchange.getAttribute(name));
}
@Override
public Map<String, Object> attributes() {
return this.exchange.getAttributes();

View File

@ -521,7 +521,7 @@ public abstract class RequestPredicates {
}
@Override
public <T> Optional<T> attribute(String name) {
public Optional<Object> attribute(String name) {
return this.request.attribute(name);
}

View File

@ -129,10 +129,17 @@ public interface ServerRequest {
/**
* Return the request attribute value if present.
* @param name the attribute name
* @param <T> the attribute type
* @return the attribute value
*/
<T> Optional<T> attribute(String name);
default Optional<Object> attribute(String name) {
Map<String, Object> attributes = attributes();
if (attributes.containsKey(name)) {
return Optional.of(attributes.get(name));
}
else {
return Optional.empty();
}
}
/**
* Return a mutable map of request attributes.

View File

@ -124,7 +124,7 @@ public class ServerRequestWrapper implements ServerRequest {
}
@Override
public <T> Optional<T> attribute(String name) {
public Optional<Object> attribute(String name) {
return this.delegate.attribute(name);
}

View File

@ -155,12 +155,6 @@ public class MockServerRequest implements ServerRequest {
return (Flux<S>) this.body;
}
@SuppressWarnings("unchecked")
@Override
public <S> Optional<S> attribute(String name) {
return Optional.ofNullable((S) this.attributes.get(name));
}
@Override
public Map<String, Object> attributes() {
return this.attributes;