Class AbstractSmartHttpMessageConverter<T>
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<T>
org.springframework.http.converter.AbstractSmartHttpMessageConverter<T>
- Type Parameters:
- T- the converted object type
- All Implemented Interfaces:
- HttpMessageConverter<T>,- SmartHttpMessageConverter<T>
- Direct Known Subclasses:
- AbstractJacksonHttpMessageConverter,- AbstractKotlinSerializationHttpMessageConverter
public abstract class AbstractSmartHttpMessageConverter<T>
extends AbstractHttpMessageConverter<T>
implements SmartHttpMessageConverter<T>
Abstract base class for most 
SmartHttpMessageConverter implementations.- Since:
- 6.2
- Author:
- Sebastien Deleuze
- 
Field SummaryFields inherited from class org.springframework.http.converter.AbstractHttpMessageConverterlogger
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstruct anAbstractSmartHttpMessageConverterwith no supported media types.protectedAbstractSmartHttpMessageConverter(MediaType supportedMediaType) Construct anAbstractSmartHttpMessageConverterwith one supported media type.protectedAbstractSmartHttpMessageConverter(MediaType... supportedMediaTypes) Construct anAbstractSmartHttpMessageConverterwith multiple supported media type.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanRead(ResolvableType type, @Nullable MediaType mediaType) Indicates whether the given type can be read by this converter.booleancanWrite(ResolvableType type, Class<?> clazz, @Nullable MediaType mediaType) Indicates whether the given class can be written by this converter.protected TreadInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) Abstract template method that reads the actual object.protected booleanIndicates whether the given class is supported by this converter.final voidwrite(T t, ResolvableType type, @Nullable MediaType contentType, HttpOutputMessage outputMessage, @Nullable Map<String, Object> hints) This implementation sets the default headers by callingAbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType), and then callswriteInternal(T, org.springframework.http.HttpOutputMessage).protected abstract voidwriteInternal(T t, ResolvableType type, HttpOutputMessage outputMessage, @Nullable Map<String, Object> hints) Abstract template method that writes the actual body.protected voidwriteInternal(T t, HttpOutputMessage outputMessage) Abstract template method that writes the actual body.Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverteraddDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, supportsRepeatableWrites, writeMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.converter.HttpMessageConvertergetSupportedMediaTypes, getSupportedMediaTypes
- 
Constructor Details- 
AbstractSmartHttpMessageConverterprotected AbstractSmartHttpMessageConverter()Construct anAbstractSmartHttpMessageConverterwith no supported media types.- See Also:
 
- 
AbstractSmartHttpMessageConverterConstruct anAbstractSmartHttpMessageConverterwith one supported media type.- Parameters:
- supportedMediaType- the supported media type
 
- 
AbstractSmartHttpMessageConverterConstruct anAbstractSmartHttpMessageConverterwith multiple supported media type.- Parameters:
- supportedMediaTypes- the supported media types
 
 
- 
- 
Method Details- 
supportsDescription copied from class:AbstractHttpMessageConverterIndicates whether the given class is supported by this converter.- Specified by:
- supportsin class- AbstractHttpMessageConverter<T>
- Parameters:
- clazz- the class to test for support
- Returns:
- trueif supported;- falseotherwise
 
- 
canReadDescription copied from interface:SmartHttpMessageConverterIndicates 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.- Specified by:
- canReadin interface- SmartHttpMessageConverter<T>
- 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
 
- 
canWriteDescription copied from interface:SmartHttpMessageConverterIndicates 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.- Specified by:
- canWritein interface- SmartHttpMessageConverter<T>
- Parameters:
- type- 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.
- clazz- 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
 
- 
writepublic final void write(T t, ResolvableType type, @Nullable MediaType contentType, HttpOutputMessage outputMessage, @Nullable Map<String, Object> hints) throws IOException, HttpMessageNotWritableExceptionThis implementation sets the default headers by callingAbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType), and then callswriteInternal(T, org.springframework.http.HttpOutputMessage).- Specified by:
- writein interface- SmartHttpMessageConverter<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.
- 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
 
- 
writeInternalprotected void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException Description copied from class:AbstractHttpMessageConverterAbstract template method that writes the actual body. Invoked fromAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage).- Specified by:
- writeInternalin class- AbstractHttpMessageConverter<T>
- Parameters:
- t- the object to write to the output message
- outputMessage- the HTTP output message to write to
- Throws:
- IOException- in case of I/O errors
- HttpMessageNotWritableException- in case of conversion errors
 
- 
writeInternalprotected abstract void writeInternal(T t, ResolvableType type, HttpOutputMessage outputMessage, @Nullable Map<String, Object> hints) throws IOException, HttpMessageNotWritableExceptionAbstract template method that writes the actual body. Invoked fromwrite(Object, ResolvableType, MediaType, HttpOutputMessage, Map).- Parameters:
- t- the object to write to the output message
- type- the type of object to write
- outputMessage- the HTTP output 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
 
- 
readInternalprotected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException Description copied from class:AbstractHttpMessageConverterAbstract template method that reads the actual object. Invoked fromAbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage).- Specified by:
- readInternalin class- AbstractHttpMessageConverter<T>
- Parameters:
- clazz- the type of object to return
- 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
 
 
-