JakeWharton/retrofit2-kotlinx-serialization-converter

Support for path/query parameters

JavierSegoviaCordoba opened this issue · 6 comments

I am using strongly typed ids (currently with data class until inline class support is available):

@Serializable
data class UserId(val value: Long)

@Serializable
data class User(val id: UserId, val name: String)

interface UsersService {

    @GET("users")
    suspend fun getUsers(): List<User> // this works

    @GET("users/{id}")
    suspend fun getUser(@Path("id") id: UserId): User // this doesn't work, because the path is `.../users/UserId(value=1)`
}

As a workaround, I added toString method to UserId

this does not affect this library and it is not a bug either, but it is a misuse

this does not affect this library and it is not a bug either, but it is a misuse

@xanscale, can you elaborate why this is a misuse?

My guess is something into the direction of "the interpolation of the placeholders in the @get strings should not rely on details of the underlying serializer".

@sschuberth first this things impact retrofit and not this converter

second, retrofit call toString() to create the final string, adding "toString" is not a woraround but the correct way

@JakeWharton you can close this UNissue

The issue is with inline classes and value classes, based on they are a wrapper over a type, having to manually write toString for them is just boilerplate IMO.

Basically is simplifying this article from Jake on Retrofit

https://jakewharton.com/inline-classes-make-great-database-ids/

Not sure how they are working at this moment in Sqldelight tho.