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

public interface SmartHttpMessageConverter<T> extends HttpMessageConverter<T>
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 Details

    • canRead

      boolean canRead(ResolvableType type, @Nullable MediaType mediaType)
      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 - 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
    • canRead

      default boolean canRead(Class<?> clazz, @Nullable MediaType mediaType)
      Description copied from interface: HttpMessageConverter
      Indicates whether the given class can be read by this converter.
      Specified by:
      canRead in interface HttpMessageConverter<T>
      Parameters:
      clazz - the class to test for readability
      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
    • read

      Read 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 canRead method 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
    • read

      default T read(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
      Description copied from interface: HttpMessageConverter
      Read an object of the given type from the given input message, and returns it.
      Specified by:
      read in interface HttpMessageConverter<T>
      Parameters:
      clazz - the type of object to return. This type must have previously been passed to the canRead method 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
    • canWrite

      boolean canWrite(ResolvableType targetType, Class<?> valueClass, @Nullable MediaType mediaType)
      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:
      targetType - 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.
      valueClass - 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
    • canWrite

      default boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType)
      Description copied from interface: HttpMessageConverter
      Indicates whether the given class can be written by this converter.
      Specified by:
      canWrite in interface HttpMessageConverter<T>
      Parameters:
      clazz - the 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

      void write(T t, ResolvableType type, @Nullable MediaType contentType, HttpOutputMessage outputMessage, @Nullable Map<String,Object> hints) throws IOException, HttpMessageNotWritableException
      Write 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 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
    • write

      default void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
      Description copied from interface: HttpMessageConverter
      Write a given object to the given output message.
      Specified by:
      write in 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 canWrite method of this interface, which must have returned true.
      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
      Throws:
      IOException - in case of I/O errors
      HttpMessageNotWritableException - in case of conversion errors