Interface SmartHttpMessageConverter<T>
- Type Parameters:
T- the converted object type
- All Superinterfaces:
HttpMessageConverter<T>
- All Known Implementing Classes:
AbstractJacksonHttpMessageConverter, AbstractKotlinSerializationHttpMessageConverter, AbstractSmartHttpMessageConverter, JacksonCborHttpMessageConverter, JacksonJsonHttpMessageConverter, JacksonSmileHttpMessageConverter, JacksonXmlHttpMessageConverter, JacksonYamlHttpMessageConverter, KotlinSerializationBinaryHttpMessageConverter, KotlinSerializationCborHttpMessageConverter, KotlinSerializationJsonHttpMessageConverter, KotlinSerializationProtobufHttpMessageConverter, KotlinSerializationStringHttpMessageConverter
A specialization of
HttpMessageConverter that can convert an HTTP request
into a target object of a specified ResolvableType and a source object of
a specified ResolvableType into an HTTP response with optional hints.
It provides default methods for HttpMessageConverter in order to allow
subclasses to only have to implement the smart APIs.
- Since:
- 6.2
- Author:
- Sebastien Deleuze
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanIndicates whether the given class can be read by this converter.booleancanRead(ResolvableType type, @Nullable MediaType mediaType) Indicates whether the given type can be read by this converter.default booleanIndicates whether the given class can be written by this converter.booleancanWrite(ResolvableType targetType, Class<?> valueClass, @Nullable MediaType mediaType) Indicates whether the given class can be written by this converter.default Tread(Class<? extends T> clazz, HttpInputMessage inputMessage) Read an object of the given type from the given input message, and returns it.read(ResolvableType type, HttpInputMessage inputMessage, @Nullable Map<String, Object> hints) Read an object of the given type from the given input message, and returns it.voidwrite(T t, ResolvableType type, @Nullable MediaType contentType, HttpOutputMessage outputMessage, @Nullable Map<String, Object> hints) Write a given object to the given output message.default voidwrite(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) Write a given object to the given output message.Methods inherited from interface HttpMessageConverter
getSupportedMediaTypes, getSupportedMediaTypes
-
Method Details
-
canRead
Indicates whether the given type can be read by this converter. This method should perform the same checks asHttpMessageConverter.canRead(Class, MediaType)with additional ones related to the generic type.- Parameters:
type- the (potentially generic) type to test for readability. The type source may be used for retrieving additional information (the related method signature for example) when relevant.mediaType- the media type to read, can benullif not specified. Typically, the value of aContent-Typeheader.- Returns:
trueif readable;falseotherwise
-
canRead
Description copied from interface:HttpMessageConverterIndicates whether the given class can be read by this converter.- Specified by:
canReadin interfaceHttpMessageConverter<T>- Parameters:
clazz- the class to test for readabilitymediaType- the media type to read (can benullif not specified); typically the value of aContent-Typeheader.- Returns:
trueif readable;falseotherwise
-
read
T read(ResolvableType type, HttpInputMessage inputMessage, @Nullable Map<String, Object> hints) throws IOException, HttpMessageNotReadableExceptionRead an object of the given type from the given input message, and returns it.- Parameters:
type- the (potentially generic) type of object to return. This type must have previously been passed to thecanReadmethod of this interface, which must have returnedtrue. The type source may be used for retrieving additional information (the related method signature for example) when relevant.inputMessage- the HTTP input message to read fromhints- additional information about how to encode- Returns:
- the converted object
- Throws:
IOException- in case of I/O errorsHttpMessageNotReadableException- in case of conversion errors
-
read
default T read(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException Description copied from interface:HttpMessageConverterRead an object of the given type from the given input message, and returns it.- Specified by:
readin interfaceHttpMessageConverter<T>- Parameters:
clazz- the type of object to return. This type must have previously been passed to thecanReadmethod of this interface, which must have returnedtrue.inputMessage- the HTTP input message to read from- Returns:
- the converted object
- Throws:
IOException- in case of I/O errorsHttpMessageNotReadableException- in case of conversion errors
-
canWrite
Indicates whether the given class can be written by this converter.This method should perform the same checks as
HttpMessageConverter.canWrite(Class, MediaType)with additional ones related to the generic type.- Parameters:
targetType- the (potentially generic) target type to test for writability (can beResolvableType.NONEif not specified). The type source may be used for retrieving additional information (the related method signature for example) when relevant.valueClass- the source object class to test for writabilitymediaType- the media type to write (can benullif not specified); typically the value of anAcceptheader.- Returns:
trueif writable;falseotherwise
-
canWrite
Description copied from interface:HttpMessageConverterIndicates whether the given class can be written by this converter.- Specified by:
canWritein interfaceHttpMessageConverter<T>- Parameters:
clazz- the class to test for writabilitymediaType- the media type to write (can benullif not specified); typically the value of anAcceptheader.- Returns:
trueif writable;falseotherwise
-
write
void write(T t, ResolvableType type, @Nullable MediaType contentType, HttpOutputMessage outputMessage, @Nullable Map<String, Object> hints) throws IOException, HttpMessageNotWritableExceptionWrite a given object to the given output message.- Parameters:
t- the object to write to the output message. The type of this object must have previously been passed to thecanWritemethod of this interface, which must have returnedtrue.type- the (potentially generic) type of object to write. This type must have previously been passed to thecanWritemethod of this interface, which must have returnedtrue. Can beResolvableType.NONEif not specified. The type source may be used for retrieving additional information (the related method signature for example) when relevant.contentType- the content type to use when writing. May benullto indicate that the default content type of the converter must be used. If notnull, this media type must have previously been passed to thecanWritemethod of this interface, which must have returnedtrue.outputMessage- the message to write tohints- additional information about how to encode- Throws:
IOException- in case of I/O errorsHttpMessageNotWritableException- in case of conversion errors
-
write
default void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException Description copied from interface:HttpMessageConverterWrite a given object to the given output message.- Specified by:
writein interfaceHttpMessageConverter<T>- Parameters:
t- the object to write to the output message. The type of this object must have previously been passed to thecanWritemethod of this interface, which must have returnedtrue.contentType- the content type to use when writing. May benullto indicate that the default content type of the converter must be used. If notnull, this media type must have previously been passed to thecanWritemethod of this interface, which must have returnedtrue.outputMessage- the message to write to- Throws:
IOException- in case of I/O errorsHttpMessageNotWritableException- in case of conversion errors
-