Thread
#serialization
    f

    fkrauthan

    2 years ago
    the return type works fine (e.g.
    MyResponse<SpecificResponse>
    as return type) but I get a no serializer found for
    MyRequest
    even though I can use serialization manual of an instance correctly.
    Jess Brent

    Jess Brent

    2 years ago
    can you paste some of your code or an example?
    f

    fkrauthan

    2 years ago
    You can see this issue in this test file: https://github.com/fkrauthan/ktor-client-issue/blob/master/src/main/kotlin/main.kt (the test project is a simple gradle project you can just pull and run yourself). It contains one success case (generic only used for response) and one failure case (generic used for request and response)
    Jess Brent

    Jess Brent

    2 years ago
    I'm away from my PC right now, if no one replies by the time I'm free I'll take a look.
    f

    fkrauthan

    2 years ago
    thank you
    Jess Brent

    Jess Brent

    2 years ago
    well i'm kinda confused because i have almost this exact same thing working for myself
    oh actually..
    f

    fkrauthan

    2 years ago
    My code fails 100% for me (and is a slightly simplified version of what I use in production)
    Jess Brent

    Jess Brent

    2 years ago
    try this:
    val request = kotlinx.serialization.json.Json {}.encodeToJsonElement(MyRequest(
                "test",
                MyEntity("Hello World")
            ))
    Running working test...successful
    Running broking test...successful
    
    Process finished with exit code 0
    as to why that works, i'm not sure
    f

    fkrauthan

    2 years ago
    Yes that works (serialization itself has no issue). I even know why it does not work as a ClientFeature. They body is passed in as a
    Any
    and to serialize it what they do is something like
    fun serialize(data: Any): String {
      val mapper = data::class.serializer()
      return json.encodeToString(mapper, data);
    }
    But
    data::class.serializer()
    Does not work well with Generics by the looks of it
    Its a hybrid issue between serialization (at least kotlinx serialization) and how the Ktor Client body payload is designed (not sure actually if ktor server response would have a similar issue)
    Jess Brent

    Jess Brent

    2 years ago
    yeah im digging to see where they call that, i think this might be something to log with ktor ^_^
    f

    fkrauthan

    2 years ago
    Yeah created a ticket with ktor: https://youtrack.jetbrains.com/issue/KTOR-1019