Package org.springframework.http.converter

# 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:
  `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 Summary

### Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter

`logger`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`AbstractSmartHttpMessageConverter()`
Construct an `AbstractSmartHttpMessageConverter` with no supported media types.
`protected`
`AbstractSmartHttpMessageConverter(MediaType supportedMediaType)`
Construct an `AbstractSmartHttpMessageConverter` with one supported media type.
`protected`
`AbstractSmartHttpMessageConverter(MediaType... supportedMediaTypes)`
Construct an `AbstractSmartHttpMessageConverter` with multiple supported media type.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`canRead(org.springframework.core.ResolvableType type, MediaType mediaType)`
Indicates whether the given type can be read by this converter.
`boolean`
`canWrite(org.springframework.core.ResolvableType type, Class<?> clazz, MediaType mediaType)`
Indicates whether the given class can be written by this converter.
`protected T`
`readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)`
Abstract template method that reads the actual object.
`protected boolean`
`supports(Class<?> clazz)`
Indicates whether the given class is supported by this converter.
`final void`
`write(T t, org.springframework.core.ResolvableType type, MediaType contentType, HttpOutputMessage outputMessage, Map<String,Object> hints)`
This implementation sets the default headers by calling `AbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType)`, and then calls `writeInternal(T, org.springframework.http.HttpOutputMessage)`.
`protected abstract void`
`writeInternal(T t, org.springframework.core.ResolvableType type, HttpOutputMessage outputMessage, Map<String,Object> hints)`
Abstract template method that writes the actual body.
`protected void`
`writeInternal(T t, HttpOutputMessage outputMessage)`
Abstract template method that writes the actual body.

### Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter

`addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, supportsRepeatableWrites, write`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.http.converter.HttpMessageConverter

`getSupportedMediaTypes, getSupportedMediaTypes`

### Methods inherited from interface org.springframework.http.converter.SmartHttpMessageConverter

`canRead, canWrite, read, read, write`

## Constructor Details

### AbstractSmartHttpMessageConverter

protected AbstractSmartHttpMessageConverter()
Construct an `AbstractSmartHttpMessageConverter` with no supported media types.

See Also:
  - `AbstractHttpMessageConverter.setSupportedMediaTypes(java.util.List<org.springframework.http.MediaType>)`

### AbstractSmartHttpMessageConverter

protected AbstractSmartHttpMessageConverter(MediaType supportedMediaType)
Construct an `AbstractSmartHttpMessageConverter` with one supported media type.

Parameters:
  `supportedMediaType` - the supported media type

### AbstractSmartHttpMessageConverter

protected AbstractSmartHttpMessageConverter(MediaType... supportedMediaTypes)
Construct an `AbstractSmartHttpMessageConverter` with multiple supported media type.

Parameters:
  `supportedMediaTypes` - the supported media types

## Method Details

### supports

protected boolean supports(Class<?> clazz)
Description copied from class: `AbstractHttpMessageConverter`
Indicates whether the given class is supported by this converter.

Specified by:
  `supports` in class `AbstractHttpMessageConverter<T>`
Parameters:
  `clazz` - the class to test for support
Returns:
  `true` if supported; `false` otherwise

### canRead

public boolean canRead(org.springframework.core.ResolvableType type, @Nullable MediaType mediaType)
Description copied from interface: `SmartHttpMessageConverter`
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.

Specified by:
  `canRead` in 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 `null` if not specified. Typically, the value of a `Content-Type` header.
Returns:
  `true` if readable; `false` otherwise

### canWrite

public boolean canWrite(org.springframework.core.ResolvableType type, Class<?> clazz, @Nullable MediaType mediaType)
Description copied from interface: `SmartHttpMessageConverter`
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.

Specified by:
  `canWrite` in interface `SmartHttpMessageConverter<T>`
Parameters:
  `type` - the (potentially generic) target type to test for writability (can be `ResolvableType.NONE` if 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 `null` if not specified); typically the value of an `Accept` header.
Returns:
  `true` if writable; `false` otherwise

### write

public final void write(T t, org.springframework.core.ResolvableType type, @Nullable MediaType contentType, HttpOutputMessage outputMessage, @Nullable Map<String,Object> hints) throws IOException, HttpMessageNotWritableException
This implementation sets the default headers by calling `AbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType)`, and then calls `writeInternal(T, org.springframework.http.HttpOutputMessage)`.

Specified by:
  `write` in 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 `canWrite` method 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 `canWrite` method of this interface, which must have returned `true`. Can be `ResolvableType.NONE` if 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 `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` - 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

### writeInternal

protected void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
Description copied from class: `AbstractHttpMessageConverter`
Abstract template method that writes the actual body. Invoked from `AbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)`.

Specified by:
  `writeInternal` in 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

### writeInternal

protected abstract void writeInternal(T t, org.springframework.core.ResolvableType type, HttpOutputMessage outputMessage, @Nullable Map<String,Object> hints) throws IOException, HttpMessageNotWritableException
Abstract template method that writes the actual body. Invoked from `write(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

### readInternal

protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
Description copied from class: `AbstractHttpMessageConverter`
Abstract template method that reads the actual object. Invoked from `AbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage)`.

Specified by:
  `readInternal` in 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