ribesg
03/06/2019, 12:04 PMio.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline: kotlinx.serialization.json.JsonParsingException: Invalid JSON at 0: Expected '[, kind: kotlinx.serialization.StructureKind$LIST@dc27766'
I’m sure that the body I’m trying to decode is correct, it does start with [{
(I’m logging it in a Before
interceptor). What could be the cause of this?e5l
03/06/2019, 12:07 PMribesg
03/06/2019, 12:08 PM[{"cityPlaceId":"03d0bb67f4a1af451d481b50f7d25b3d","city":"Grenoble","address":"Place Victor Hugo","zipCode":"38000","department":"Isère","departmentShort":"38","state":"Auvergne-Rhône-Alpes","stateShort":"Auvergne-Rhône-Alpes","country":"France","countryShort":"FR","geo":{"lat":45.1884,"lon":5.7241,"valid":true},"valid":true,"type":"ADDRESS"},{"cityPlaceId":"2e19616943c1f9907b3d1999527cff5c","city":"Grenoble","address":"Rue Lamartine","zipCode":"38000","department":"Isère","departmentShort":"38","state":"Auvergne-Rhône-Alpes","stateShort":"Auvergne-Rhône-Alpes","country":"France","countryShort":"FR","geo":{"lat":45.188,"lon":5.7248,"valid":true},"valid":true,"type":"ADDRESS"},{"cityPlaceId":"0780be60e6e5a287bc8fd09eeb135620","city":"Grenoble","address":"Rue Béranger","zipCode":"38000","department":"Isère","departmentShort":"38","state":"Auvergne-Rhône-Alpes","stateShort":"Auvergne-Rhône-Alpes","country":"France","countryShort":"FR","geo":{"lat":45.188,"lon":5.724,"valid":true},"valid":true,"type":"ADDRESS"},{"cityPlaceId":"ce418e78067392a63742b4f4ce875f7b","city":"Grenoble","address":"Rue Vauban","zipCode":"38000","department":"Isère","departmentShort":"38","state":"Auvergne-Rhône-Alpes","stateShort":"Auvergne-Rhône-Alpes","country":"France","countryShort":"FR","geo":{"lat":45.1884,"lon":5.7236,"valid":true},"valid":true,"type":"ADDRESS"},{"cityPlaceId":"9ad7984550240c9ceb762bf29598deea","city":"Grenoble","address":"Rue Paul Bert","zipCode":"38000","department":"Isère","departmentShort":"38","state":"Auvergne-Rhône-Alpes","stateShort":"Auvergne-Rhône-Alpes","country":"France","countryShort":"FR","geo":{"lat":45.1882,"lon":5.7254,"valid":true},"valid":true,"type":"ADDRESS"}]
@Serializable
data class PlaceApiLocation(
val city: String?,
val country: String
)
@Serializable
internal data class PlaceApiLocations(
val list: List<PlaceApiLocation>
) {
@Serializer(PlaceApiLocations::class)
companion object : KSerializer<PlaceApiLocations> {
override val descriptor = StringDescriptor.withName(PlaceApiLocations::class.simpleName!!)
override fun serialize(encoder: Encoder, obj: PlaceApiLocations) {
PlaceApiLocation.serializer().list.serialize(encoder, obj.list)
}
override fun deserialize(decoder: Decoder): PlaceApiLocations {
return PlaceApiLocations(PlaceApiLocation.serializer().list.deserialize(decoder))
}
}
}
e5l
03/06/2019, 12:09 PMribesg
03/06/2019, 12:33 PMreceivePipeline.intercept(HttpReceivePipeline.Before) {
HttpLogger.logResponse(subject)
}
instead of ResponseObserver.install(ResponseObserver {
HttpLogger.logResponse(it)
}, this)
so my logger was consuming the response body before it got to the deserializer, which tried to deserialize an empty String