Top Description Fields Constructors Methods
org.springframework.http.converter

public abstract Class AbstractGenericHttpMessageConverter<T>

extends AbstractHttpMessageConverter<T>
implements GenericHttpMessageConverter<T>
Class Inheritance
All Implemented Interfaces
org.springframework.http.converter.GenericHttpMessageConverter, org.springframework.http.converter.HttpMessageConverter
Known Direct Subclasses
org.springframework.http.converter.AbstractKotlinSerializationHttpMessageConverter, org.springframework.http.converter.ResourceRegionHttpMessageConverter, org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter, org.springframework.http.converter.json.AbstractJsonHttpMessageConverter
Type Parameters
<T>
the converted object type
Imports
java.io.IOException, .OutputStream, java.lang.reflect.Type, org.springframework.http.HttpHeaders, .HttpOutputMessage, .MediaType, .StreamingHttpOutputMessage, org.springframework.lang.Nullable

Abstract base class for most GenericHttpMessageConverter implementations.
Authors
Sebastien Deleuze, Juergen Hoeller
Since
4.2

Field Summary

Inherited from org.springframework.http.converter.AbstractHttpMessageConverter:
logger

Constructor Summary

AccessConstructor and Description
protected
AbstractGenericHttpMessageConverter()

Construct an AbstractGenericHttpMessageConverter with no supported media types.

protected
AbstractGenericHttpMessageConverter(MediaType
the supported media type
supportedMediaType
)

Construct an AbstractGenericHttpMessageConverter with one supported media type.

protected
AbstractGenericHttpMessageConverter(MediaType...
the supported media types
supportedMediaTypes
)

Construct an AbstractGenericHttpMessageConverter with multiple supported media type.

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(Type
the (potentially generic) type to test for readability
type
,
Class<?>
a context class for the target type, for example a class in which the target type appears in a method signature (can be null)
contextClass
,
MediaType
the media type to read, can be null if not specified. Typically, the value of a Content-Type header.
mediaType
)

Implements org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Indicates whether the given type can be read by this converter.

public boolean
canWrite(Type
the (potentially generic) type to test for writability (can be null if not specified)
type
,
Class<?>
the source object class to test for writability
clazz
,
MediaType
the media type to write (can be null if not specified); typically the value of an Accept header.
mediaType
)

Implements org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Indicates whether the given class can be written by this converter.

protected boolean
supports(Class<?>
the class to test for support
clazz
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.

public final void
write(final T
the object to write to the output message. The type of this object must have previously been passed to the canWrite method of this interface, which must have returned true.
t
,
final Type
the (potentially generic) type of object to write. This type must have previously been passed to the canWrite method of this interface, which must have returned true. Can be null if not specified.
type
,
MediaType
the content type to use when writing. May be null to 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 canWrite method of this interface, which must have returned true.
contentType
,
HttpOutputMessage
the message to write to
outputMessage
)

Implements org.springframework.http.converter.GenericHttpMessageConverter.write.

This implementation sets the default headers by calling addDefaultHeaders, and then calls writeInternal.

protected void
writeInternal(T
the object to write to the output message
t
,
HttpOutputMessage
the HTTP output message to write to
outputMessage
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body.

protected abstract void
writeInternal(T
the object to write to the output message
t
,
Type
the type of object to write (may be null)
type
,
HttpOutputMessage
the HTTP output message to write to
outputMessage
)

Abstract template method that writes the actual body.

Inherited from org.springframework.http.converter.AbstractHttpMessageConverter:
addDefaultHeaderscanReadcanReadcanWritecanWritegetContentLengthgetDefaultCharsetgetDefaultContentTypegetSupportedMediaTypesreadreadInternalsetDefaultCharsetsetSupportedMediaTypessupportsRepeatableWriteswrite

Constructor Detail

AbstractGenericHttpMessageConverterback to summary
protected AbstractGenericHttpMessageConverter()

Construct an AbstractGenericHttpMessageConverter with no supported media types.

See Also
setSupportedMediaTypes
AbstractGenericHttpMessageConverterback to summary
protected AbstractGenericHttpMessageConverter(MediaType supportedMediaType)

Construct an AbstractGenericHttpMessageConverter with one supported media type.

Parameters
supportedMediaType:MediaType

the supported media type

AbstractGenericHttpMessageConverterback to summary
protected AbstractGenericHttpMessageConverter(MediaType... supportedMediaTypes)

Construct an AbstractGenericHttpMessageConverter with multiple supported media type.

Parameters
supportedMediaTypes:MediaType[]

the supported media types

Method Detail

canReadback to summary
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType)

Implements org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Indicates whether the given type can be read by this converter. This method should perform the same checks as HttpMessageConverter#canRead(Class, MediaType) with additional ones related to the generic type.

Parameters
type:Type

the (potentially generic) type to test for readability

contextClass:Class<?>

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:MediaType

the media type to read, can be null if not specified. Typically, the value of a Content-Type header.

Returns:boolean

true if readable; false otherwise

Annotations
@Override
canWriteback to summary
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType)

Implements org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.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
type:Type

the (potentially generic) type to test for writability (can be null if not specified)

clazz:Class<?>

the source object class to test for writability

mediaType:MediaType

the media type to write (can be null if not specified); typically the value of an Accept header.

Returns:boolean

true if writable; false otherwise

Annotations
@Override
supportsback to summary
protected boolean supports(Class<?> clazz)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.

Parameters
clazz:Class<?>

the class to test for support

Returns:boolean

true if supported; false otherwise

Annotations
@Override
writeback to summary
public final void write(final T t, final Type type, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException

Implements org.springframework.http.converter.GenericHttpMessageConverter.write.

This implementation sets the default headers by calling addDefaultHeaders, and then calls writeInternal.

Parameters
t:T

Doc from org.springframework.http.converter.GenericHttpMessageConverter.write.

the object to write to the output message. The type of this object must have previously been passed to the canWrite method of this interface, which must have returned true.

type:Type

Doc from org.springframework.http.converter.GenericHttpMessageConverter.write.

the (potentially generic) type of object to write. This type must have previously been passed to the canWrite method of this interface, which must have returned true. Can be null if not specified.

contentType:MediaType

Doc from org.springframework.http.converter.GenericHttpMessageConverter.write.

the content type to use when writing. May be null to 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 canWrite method of this interface, which must have returned true.

outputMessage:HttpOutputMessage

Doc from org.springframework.http.converter.GenericHttpMessageConverter.write.

the message to write to

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.http.converter.GenericHttpMessageConverter.write.

in case of I/O errors

HttpMessageNotWritableException:

Doc from org.springframework.http.converter.GenericHttpMessageConverter.write.

in case of conversion errors

writeInternalback to summary
protected void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.writeInternal.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body. Invoked from write.

Parameters
t:T

the object to write to the output message

outputMessage:HttpOutputMessage

the HTTP output message to write to

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
HttpMessageNotWritableException:
in case of conversion errors
writeInternalback to summary
protected abstract void writeInternal(T t, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException

Abstract template method that writes the actual body. Invoked from write.

Parameters
t:T

the object to write to the output message

type:Type

the type of object to write (may be null)

outputMessage:HttpOutputMessage

the HTTP output message to write to

Exceptions
IOException:
in case of I/O errors
HttpMessageNotWritableException:
in case of conversion errors