Example usage for org.springframework.core ResolvableType toClass

List of usage examples for org.springframework.core ResolvableType toClass

Introduction

In this page you can find the example usage for org.springframework.core ResolvableType toClass.

Prototype

public Class<?> toClass() 

Source Link

Document

Return this type as a resolved Class , falling back to java.lang.Object if no specific class can be resolved.

Usage

From source file:org.springframework.http.codec.multipart.DefaultMultipartMessageReader.java

@Override
public boolean canRead(ResolvableType elementType, @Nullable MediaType mediaType) {
    return (Part.class.equals(elementType.toClass())
            && (mediaType == null || MediaType.MULTIPART_FORM_DATA.isCompatibleWith(mediaType)));
}

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;//from  w  ww. j ava2s .  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));
}