All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uidsonic.fluid-json-ktor-client.0.9.19.source-code.FluidJsonSerializer.kt Maven / Gradle / Ivy

There is a newer version: 0.9.24
Show newest version
@file:Suppress("INVISIBLE_MEMBER")

package com.github.fluidsonic.fluid.json

import io.ktor.client.call.*
import io.ktor.client.features.json.*
import io.ktor.client.response.*
import io.ktor.content.TextContent
import io.ktor.http.*
import io.ktor.http.content.*


class FluidJsonSerializer(
	private val parser: JSONCodingParser<*> = JSONCodingParser.nonRecursive,
	private val serializer: JSONCodingSerializer = JSONCodingSerializer.nonRecursive
) : JsonSerializer {

	override suspend fun read(type: TypeInfo, response: HttpResponse) =
		parser.parseValueOfType(response.readText(), JSONCodingType.of(type.reifiedType))


	override fun write(data: Any): OutgoingContent =
		TextContent(serializer.serializeValue(data), ContentType.Application.Json)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy