Ktor: http client won't deserialize JSON?

Created on 20 Dec 2018  路  1Comment  路  Source: ktorio/ktor

Ktor Version

Latest

Ktor Engine Used(client or server and name)

HTTP Client

JVM Version, Operating System and Relevant Context

Java 11

Feedback

I get the following error:

Caused by: io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.client.features.observer.DelegatedResponse -> class com.flexshopper.kraken.geolocation.search.retailers.RetailerFetchResult

And I'm not sure what I'm doing wrong... I seem to have followed the example, right?

data class TiresVendor(
    val vendorName: String,
    var street1: String,
    val street2: String?,
    val city: String,
    val region: String,
    val zip: String,
    val displayName: String = vendorName.replace(Regex("(.+?)(NTB|MDT|TBC)"), "$2 #$1")
)

@JsonIgnoreProperties("_links")
class RetailerFetchResult<T>(
    private val pageCount: Int,
    private val pageSize: Int,
    private val totalItems: Int,
    private val page: Int
) {
    private lateinit var vendors: List<T>

    @JsonProperty("_embedded")
    fun parseTireRetailers(retailers: Map<String, List<T>>) {
        vendors = retailers["tire-retailers"]!!
    }

    override fun toString(): String {
        return "RetailerFetchResult(pageCount=$pageCount, " +
            "pageSize=$pageSize, totalItems=$totalItems, page=$page, vendors=$vendors)"
    }
}

class TireRetailersFetcher(private val baseUrl: String) {
    suspend fun fetch(): RetailerFetchResult<TiresVendor> {
        val client = HttpClient {
            install(JsonFeature) {
                serializer = JacksonSerializer {
                }
            }

            install(Logging) {
                level = LogLevel.HEADERS
            }
        }

        return client.get(baseUrl) {
            contentType(ContentType.Application.Json)
        }
    }
}

Most helpful comment

Needed to specify accept(ContentType.Application.Json) manually.

>All comments

Needed to specify accept(ContentType.Application.Json) manually.

Was this page helpful?
0 / 5 - 0 ratings