List of usage examples for org.springframework.core KotlinDetector isKotlinReflectPresent
public static boolean isKotlinReflectPresent()
From source file:org.springframework.messaging.handler.invocation.reactive.AbstractEncoderMethodReturnValueHandler.java
@SuppressWarnings("unchecked") private Flux<DataBuffer> encodeContent(@Nullable Object content, MethodParameter returnType, DataBufferFactory bufferFactory, @Nullable MimeType mimeType, Map<String, Object> hints) { ResolvableType returnValueType = ResolvableType.forMethodParameter(returnType); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(returnValueType.resolve(), content); Publisher<?> publisher;// ww w . j a va2s .c om ResolvableType elementType; if (adapter != null) { publisher = adapter.toPublisher(content); boolean isUnwrapped = KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(returnType.getContainingClass()) && KotlinDelegate.isSuspend(returnType.getMethod()) && !COROUTINES_FLOW_CLASS_NAME.equals(returnValueType.toClass().getName()); ResolvableType genericType = isUnwrapped ? returnValueType : returnValueType.getGeneric(); elementType = getElementType(adapter, genericType); } else { publisher = Mono.justOrEmpty(content); elementType = (returnValueType.toClass() == Object.class && content != null ? ResolvableType.forInstance(content) : returnValueType); } if (elementType.resolve() == void.class || elementType.resolve() == Void.class) { return Flux.from(publisher).cast(DataBuffer.class); } Encoder<?> encoder = getEncoder(elementType, mimeType); return Flux.from((Publisher) publisher) .map(value -> encodeValue(value, elementType, encoder, bufferFactory, mimeType, hints)); }