Merge branch '5.1.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -118,13 +118,10 @@ public final class Conventions {
|
||||
}
|
||||
else {
|
||||
valueClass = parameter.getParameterType();
|
||||
ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||
if (reactiveAdapterRegistry.hasAdapters()) {
|
||||
ReactiveAdapter adapter = reactiveAdapterRegistry.getAdapter(valueClass);
|
||||
if (adapter != null && !adapter.getDescriptor().isNoValue()) {
|
||||
reactiveSuffix = ClassUtils.getShortName(valueClass);
|
||||
valueClass = parameter.nested().getNestedParameterType();
|
||||
}
|
||||
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(valueClass);
|
||||
if (adapter != null && !adapter.getDescriptor().isNoValue()) {
|
||||
reactiveSuffix = ClassUtils.getShortName(valueClass);
|
||||
valueClass = parameter.nested().getNestedParameterType();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,13 +204,10 @@ public final class Conventions {
|
||||
}
|
||||
else {
|
||||
valueClass = resolvedType;
|
||||
ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||
if (reactiveAdapterRegistry.hasAdapters()) {
|
||||
ReactiveAdapter adapter = reactiveAdapterRegistry.getAdapter(valueClass);
|
||||
if (adapter != null && !adapter.getDescriptor().isNoValue()) {
|
||||
reactiveSuffix = ClassUtils.getShortName(valueClass);
|
||||
valueClass = ResolvableType.forMethodReturnType(method).getGeneric().toClass();
|
||||
}
|
||||
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(valueClass);
|
||||
if (adapter != null && !adapter.getDescriptor().isNoValue()) {
|
||||
reactiveSuffix = ClassUtils.getShortName(valueClass);
|
||||
valueClass = ResolvableType.forMethodReturnType(method).getGeneric().toClass();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ReactiveAdapterRegistry {
|
||||
|
||||
private final boolean reactorPresent;
|
||||
|
||||
private final List<ReactiveAdapter> adapters = new ArrayList<>(32);
|
||||
private final List<ReactiveAdapter> adapters = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -67,7 +67,6 @@ public class ReactiveAdapterRegistry {
|
||||
* @see #getSharedInstance()
|
||||
*/
|
||||
public ReactiveAdapterRegistry() {
|
||||
|
||||
ClassLoader classLoader = ReactiveAdapterRegistry.class.getClassLoader();
|
||||
|
||||
// Reactor
|
||||
@@ -118,8 +117,8 @@ public class ReactiveAdapterRegistry {
|
||||
|
||||
/**
|
||||
* Register a reactive type along with functions to adapt to and from a
|
||||
* Reactive Streams {@link Publisher}. The functions can assume their
|
||||
* input is never be {@code null} nor {@link Optional}.
|
||||
* Reactive Streams {@link Publisher}. The function arguments assume that
|
||||
* their input is neither {@code null} nor {@link Optional}.
|
||||
*/
|
||||
public void registerReactiveType(ReactiveTypeDescriptor descriptor,
|
||||
Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter) {
|
||||
@@ -134,6 +133,7 @@ public class ReactiveAdapterRegistry {
|
||||
|
||||
/**
|
||||
* Get the adapter for the given reactive type.
|
||||
* @return the corresponding adapter, or {@code null} if none available
|
||||
*/
|
||||
@Nullable
|
||||
public ReactiveAdapter getAdapter(Class<?> reactiveType) {
|
||||
@@ -147,20 +147,25 @@ public class ReactiveAdapterRegistry {
|
||||
* (may be {@code null} if a concrete source object is given)
|
||||
* @param source an instance of the reactive type
|
||||
* (i.e. to adapt from; may be {@code null} if the reactive type is specified)
|
||||
* @return the corresponding adapter, or {@code null} if none available
|
||||
*/
|
||||
@Nullable
|
||||
public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, @Nullable Object source) {
|
||||
if (this.adapters.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object sourceToUse = (source instanceof Optional ? ((Optional<?>) source).orElse(null) : source);
|
||||
Class<?> clazz = (sourceToUse != null ? sourceToUse.getClass() : reactiveType);
|
||||
if (clazz == null) {
|
||||
return null;
|
||||
}
|
||||
for(ReactiveAdapter adapter : this.adapters) {
|
||||
for (ReactiveAdapter adapter : this.adapters) {
|
||||
if (adapter.getReactiveType() == clazz) {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
for(ReactiveAdapter adapter : this.adapters) {
|
||||
for (ReactiveAdapter adapter : this.adapters) {
|
||||
if (adapter.getReactiveType().isAssignableFrom(clazz)) {
|
||||
return adapter;
|
||||
}
|
||||
@@ -170,13 +175,13 @@ public class ReactiveAdapterRegistry {
|
||||
|
||||
|
||||
/**
|
||||
* Return a shared default {@code ReactiveAdapterRegistry} instance, lazily
|
||||
* building it once needed.
|
||||
* Return a shared default {@code ReactiveAdapterRegistry} instance,
|
||||
* lazily building it once needed.
|
||||
* <p><b>NOTE:</b> We highly recommend passing a long-lived, pre-configured
|
||||
* {@code ReactiveAdapterRegistry} instance for customization purposes.
|
||||
* This accessor is only meant as a fallback for code paths that want to
|
||||
* fall back on a default instance if one isn't provided.
|
||||
* @return the shared {@code ReactiveAdapterRegistry} instance (never {@code null})
|
||||
* @return the shared {@code ReactiveAdapterRegistry} instance
|
||||
* @since 5.0.2
|
||||
*/
|
||||
public static ReactiveAdapterRegistry getSharedInstance() {
|
||||
|
||||
@@ -40,10 +40,10 @@ import org.springframework.util.MimeType;
|
||||
*/
|
||||
public abstract class AbstractDecoder<T> implements Decoder<T> {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final List<MimeType> decodableMimeTypes;
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
protected AbstractDecoder(MimeType... supportedMimeTypes) {
|
||||
this.decodableMimeTypes = Arrays.asList(supportedMimeTypes);
|
||||
|
||||
@@ -36,10 +36,10 @@ import org.springframework.util.MimeType;
|
||||
*/
|
||||
public abstract class AbstractEncoder<T> implements Encoder<T> {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final List<MimeType> encodableMimeTypes;
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
protected AbstractEncoder(MimeType... supportedMimeTypes) {
|
||||
this.encodableMimeTypes = Arrays.asList(supportedMimeTypes);
|
||||
|
||||
@@ -74,32 +74,32 @@ final class CompositeLog implements Log {
|
||||
|
||||
@Override
|
||||
public boolean isFatalEnabled() {
|
||||
return this.fatalLogger != NO_OP_LOG;
|
||||
return (this.fatalLogger != NO_OP_LOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return this.errorLogger != NO_OP_LOG;
|
||||
return (this.errorLogger != NO_OP_LOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return this.warnLogger != NO_OP_LOG;
|
||||
return (this.warnLogger != NO_OP_LOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return this.infoLogger != NO_OP_LOG;
|
||||
return (this.infoLogger != NO_OP_LOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return this.debugLogger != NO_OP_LOG;
|
||||
return (this.debugLogger != NO_OP_LOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return this.traceLogger != NO_OP_LOG;
|
||||
return (this.traceLogger != NO_OP_LOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user