Interface SmartHttpMessageConverter<T>
- Type Parameters:
- T- the converted object type
- All Superinterfaces:
- HttpMessageConverter<T>
- All Known Implementing Classes:
- AbstractKotlinSerializationHttpMessageConverter,- AbstractSmartHttpMessageConverter,- 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 SummaryModifier and TypeMethodDescriptiondefault booleanIndicates whether the given class can be read by this converter.booleancanRead(ResolvableType type, 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, 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, Map<String, Object> hints) Read an object of the given type from the given input message, and returns it.voidwrite(T t, ResolvableType type, MediaType contentType, HttpOutputMessage outputMessage, Map<String, Object> hints) Write a given object to the given output message.default voidwrite(T t, MediaType contentType, HttpOutputMessage outputMessage) Write a given object to the given output message.Methods inherited from interface org.springframework.http.converter.HttpMessageConvertergetSupportedMediaTypes, getSupportedMediaTypes
- 
Method Details- 
canReadIndicates 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 be- nullif not specified. Typically, the value of a- Content-Typeheader.
- Returns:
- trueif readable;- falseotherwise
 
- 
canReadDescription copied from interface:HttpMessageConverterIndicates whether the given class can be read by this converter.- Specified by:
- canReadin interface- HttpMessageConverter<T>
- Parameters:
- clazz- the class to test for readability
- mediaType- the media type to read (can be- nullif not specified); typically the value of a- Content-Typeheader.
- Returns:
- trueif readable;- falseotherwise
 
- 
readT 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 the- canReadmethod of this interface, which must have returned- true. 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 from
- hints- additional information about how to encode
- Returns:
- the converted object
- Throws:
- IOException- in case of I/O errors
- HttpMessageNotReadableException- in case of conversion errors
 
- 
readdefault 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 interface- HttpMessageConverter<T>
- Parameters:
- clazz- the type of object to return. This type must have previously been passed to the- canReadmethod of this interface, which must have returned- true.
- inputMessage- the HTTP input message to read from
- Returns:
- the converted object
- Throws:
- IOException- in case of I/O errors
- HttpMessageNotReadableException- in case of conversion errors
 
- 
canWriteIndicates 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 be- ResolvableType.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 writability
- mediaType- the media type to write (can be- nullif not specified); typically the value of an- Acceptheader.
- Returns:
- trueif writable;- falseotherwise
 
- 
canWriteDescription copied from interface:HttpMessageConverterIndicates whether the given class can be written by this converter.- Specified by:
- canWritein interface- HttpMessageConverter<T>
- Parameters:
- clazz- the class to test for writability
- mediaType- the media type to write (can be- nullif not specified); typically the value of an- Acceptheader.
- Returns:
- trueif writable;- falseotherwise
 
- 
writevoid 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 the- canWritemethod of this interface, which must have returned- true.
- type- the (potentially generic) type of object to write. This type must have previously been passed to the- canWritemethod of this interface, which must have returned- true. Can be- ResolvableType.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 be- nullto indicate that the default content type of the converter must be used. If not- null, this media type must have previously been passed to the- canWritemethod of this interface, which must have returned- true.
- outputMessage- the message to write to
- hints- additional information about how to encode
- Throws:
- IOException- in case of I/O errors
- HttpMessageNotWritableException- in case of conversion errors
 
- 
writedefault 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 interface- HttpMessageConverter<T>
- Parameters:
- t- the object to write to the output message. The type of this object must have previously been passed to the- canWritemethod of this interface, which must have returned- true.
- contentType- the content type to use when writing. May be- nullto indicate that the default content type of the converter must be used. If not- null, this media type must have previously been passed to the- canWritemethod of this interface, which must have returned- true.
- outputMessage- the message to write to
- Throws:
- IOException- in case of I/O errors
- HttpMessageNotWritableException- in case of conversion errors
 
 
-