Class AbstractGenericHttpMessageConverter<T>
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<T>
org.springframework.http.converter.AbstractGenericHttpMessageConverter<T>
- Type Parameters:
- T- the converted object type
- All Implemented Interfaces:
- GenericHttpMessageConverter<T>, HttpMessageConverter<T>
- Direct Known Subclasses:
- AbstractJackson2HttpMessageConverter, AbstractJsonHttpMessageConverter, ResourceRegionHttpMessageConverter
public abstract class AbstractGenericHttpMessageConverter<T>
extends AbstractHttpMessageConverter<T>
implements GenericHttpMessageConverter<T>
Abstract base class for most 
GenericHttpMessageConverter implementations.- Since:
- 4.2
- Author:
- Sebastien Deleuze, Juergen Hoeller
- 
Field SummaryFields inherited from class AbstractHttpMessageConverterlogger
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstruct anAbstractGenericHttpMessageConverterwith no supported media types.protectedAbstractGenericHttpMessageConverter(Charset defaultCharset, MediaType... supportedMediaTypes) Construct anAbstractGenericHttpMessageConverterwith a default charset and multiple supported media types.protectedAbstractGenericHttpMessageConverter(MediaType supportedMediaType) Construct anAbstractGenericHttpMessageConverterwith one supported media type.protectedAbstractGenericHttpMessageConverter(MediaType... supportedMediaTypes) Construct anAbstractGenericHttpMessageConverterwith multiple supported media type.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanIndicates whether the given type can be read by this converter.booleanIndicates whether the given class can be written by this converter.protected booleanIndicates whether the given class is supported by this converter.final voidThis implementation sets the default headers by callingAbstractHttpMessageConverter.addDefaultHeaders(HttpHeaders, T, MediaType), and then callswriteInternal(T, HttpOutputMessage).protected abstract voidwriteInternal(T t, @Nullable Type type, HttpOutputMessage outputMessage) 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 AbstractHttpMessageConverteraddDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, readInternal, setDefaultCharset, setSupportedMediaTypes, supportsRepeatableWrites, writeMethods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GenericHttpMessageConverterreadMethods inherited from interface HttpMessageConvertercanRead, canWrite, getSupportedMediaTypes, getSupportedMediaTypes, read, write
- 
Constructor Details- 
AbstractGenericHttpMessageConverterprotected AbstractGenericHttpMessageConverter()Construct anAbstractGenericHttpMessageConverterwith no supported media types.- See Also:
 
- 
AbstractGenericHttpMessageConverterConstruct anAbstractGenericHttpMessageConverterwith one supported media type.- Parameters:
- supportedMediaType- the supported media type
 
- 
AbstractGenericHttpMessageConverterConstruct anAbstractGenericHttpMessageConverterwith multiple supported media type.- Parameters:
- supportedMediaTypes- the supported media types
 
- 
AbstractGenericHttpMessageConverterprotected AbstractGenericHttpMessageConverter(Charset defaultCharset, MediaType... supportedMediaTypes) Construct anAbstractGenericHttpMessageConverterwith a default charset and multiple supported media types.- Parameters:
- defaultCharset- the default character set
- supportedMediaTypes- the supported media types
- Since:
- 6.2
 
 
- 
- 
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:GenericHttpMessageConverterIndicates 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- GenericHttpMessageConverter<T>
- Parameters:
- type- the (potentially generic) type to test for readability
- contextClass- a context class for the target type, for example a class in which the target type appears in a method signature (can be- null)
- 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:GenericHttpMessageConverterIndicates 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- GenericHttpMessageConverter<T>
- Parameters:
- type- the (potentially generic) type to test for writability (can be- nullif not specified)
- 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, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException This implementation sets the default headers by callingAbstractHttpMessageConverter.addDefaultHeaders(HttpHeaders, T, MediaType), and then callswriteInternal(T, HttpOutputMessage).- Specified by:
- writein interface- GenericHttpMessageConverter<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- nullif not specified.
- 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
 
- 
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, MediaType, 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, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException Abstract template method that writes the actual body. Invoked fromwrite(T, Type, MediaType, HttpOutputMessage).- Parameters:
- t- the object to write to the output message
- type- the type of object to write (may be- null)
- outputMessage- the HTTP output message to write to
- Throws:
- IOException- in case of I/O errors
- HttpMessageNotWritableException- in case of conversion errors
 
 
-