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:
parent
dfcc9af938
commit
e11bb17aa6
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue