Skip to content

Commit

Permalink
fix: list parsing error (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso authored Jun 3, 2023
1 parent 11399f4 commit 1e83f43
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
### :thinking: DOD Checklist

- [ ] My changes are covered with proper tests.
- [ ] I did all relevant changes to the documentation and the [changelog](https://github.com/Foso/Ktorfit/blob/master/docs/CHANGELOG.md).
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Removed

### Fixed
#236 Parsing error for list/array

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ public class Ktorfit private constructor(
baseUrl = _baseUrl,
httpClient = _httpClient,
responseConverters = _responseConverter,
suspendResponseConverters = _suspendResponseConverter.also {
it.add(DefaultSuspendResponseConverterFactory())
},
suspendResponseConverters = _suspendResponseConverter,
requestConverters = _requestConverter,
converterFactories = listOf(KtorfitDefaultConverterFactory()) + _factories.toList()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package de.jensklingenberg.ktorfit.converter.builtin

import de.jensklingenberg.ktorfit.Ktorfit
import de.jensklingenberg.ktorfit.converter.Converter
import de.jensklingenberg.ktorfit.converter.SuspendResponseConverter
import de.jensklingenberg.ktorfit.internal.TypeData
import io.ktor.client.call.*
import io.ktor.client.statement.*
import io.ktor.util.reflect.*

/**
* Will be used when no other suspend converter was found
* It is automatically applied last
*/
internal class DefaultSuspendResponseConverterFactory : Converter.Factory, SuspendResponseConverter {
internal class DefaultSuspendResponseConverterFactory : Converter.Factory {

class DefaultSuspendResponseConverter(val typeData: TypeData) :
Converter.SuspendResponseConverter<HttpResponse, Any> {
Expand All @@ -28,21 +25,9 @@ internal class DefaultSuspendResponseConverterFactory : Converter.Factory, Suspe
override fun suspendResponseConverter(
typeData: TypeData,
ktorfit: Ktorfit
): Converter.SuspendResponseConverter<HttpResponse, *>? {
): Converter.SuspendResponseConverter<HttpResponse, *> {
return DefaultSuspendResponseConverter(typeData)
}

override suspend fun <RequestType> wrapSuspendResponse(
typeData: TypeData,
requestFunction: suspend () -> Pair<TypeInfo, HttpResponse>,
ktorfit: Ktorfit
): Any {
val (info, response) = requestFunction()
return response.body(info)
}

override fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {
return true
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.jensklingenberg.ktorfit.internal

import de.jensklingenberg.ktorfit.Ktorfit
import de.jensklingenberg.ktorfit.converter.builtin.DefaultSuspendResponseConverterFactory
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
Expand Down Expand Up @@ -93,6 +94,11 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client {
*/
handleDeprecatedSuspendResponseConverters<ReturnType, RequestType>(requestData)?.let {
return it
} ?: DefaultSuspendResponseConverterFactory().suspendResponseConverter(returnTypeData, ktorfit)?.let {
val response = httpClient.request {
requestBuilder(requestData)
}
return it.convert(response) as ReturnType?
} ?: throw IllegalStateException("No SuspendResponseConverter found for " + returnTypeData.qualifiedName)

} catch (exception: Exception) {
Expand Down

0 comments on commit 1e83f43

Please sign in to comment.