ContentConverter

A custom content converter that could be registered in ContentNegotiation plugin for any particular content type Could provide bi-directional conversion implementation. One of the most typical examples of content converter is a JSON content converter that provides both serialization and deserialization

Implementations must override at least one of serialize or serializeNullable methods.

Functions

Link copied to clipboard
abstract suspend fun deserialize(charset: Charset, typeInfo: TypeInfo, content: ByteReadChannel): Any?

Deserializes content to the value of type typeInfo

Link copied to clipboard
open suspend fun serialize(contentType: ContentType, charset: Charset, typeInfo: TypeInfo, value: Any): OutgoingContent?

Serializes a value to the specified contentType to a OutgoingContent. This function could ignore value if it is not suitable for conversion and return null so in this case other registered converters could be tried or this function could be invoked with other content types it the converted has been registered multiple times with different content types.

Link copied to clipboard
open suspend fun serializeNullable(contentType: ContentType, charset: Charset, typeInfo: TypeInfo, value: Any?): OutgoingContent?

Serializes a value to the specified contentType to a OutgoingContent. This function could ignore value if it is not suitable for conversion and return null so in this case other registered converters could be tried or this function could be invoked with other content types it the converted has been registered multiple times with different content types.