Example usage for org.springframework.core.codec Encoder encodeValue

List of usage examples for org.springframework.core.codec Encoder encodeValue

Introduction

In this page you can find the example usage for org.springframework.core.codec Encoder encodeValue.

Prototype

default DataBuffer encodeValue(T value, DataBufferFactory bufferFactory, ResolvableType valueType,
        @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) 

Source Link

Document

Encode an Object of type T to a data buffer.

Usage

From source file:org.springframework.messaging.handler.invocation.reactive.AbstractEncoderMethodReturnValueHandler.java

@SuppressWarnings("unchecked")
private <T> DataBuffer encodeValue(Object element, ResolvableType elementType, @Nullable Encoder<T> encoder,
        DataBufferFactory bufferFactory, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

    if (encoder == null) {
        encoder = getEncoder(ResolvableType.forInstance(element), mimeType);
        if (encoder == null) {
            throw new MessagingException(
                    "No encoder for " + elementType + ", current value type is " + element.getClass());
        }//  w  w  w .jav a2s  .  c  o m
    }
    return encoder.encodeValue((T) element, bufferFactory, elementType, mimeType, hints);
}