Coder Social home page Coder Social logo

Comments (5)

Maxr1998 avatar Maxr1998 commented on May 20, 2024

If you pass classes as parameters, you could define reified inline extension functions afterwards, like so:

import kotlin.reflect.KClass

interface ApiClient {
    fun <T: Any> get(clazz: KClass<T>): T
}

inline fun <reified T: Any> ApiClient.get(): T = get(T::class)

from jellyfin-sdk-kotlin.

nielsvanvelzen avatar nielsvanvelzen commented on May 20, 2024

The reified fun's are not in the interface so we won't be able to use the interface in the generated API classes with that approach, besides. Ktor doesn't allow passing the return type as a class, they ONLY support reified types (not sure why they chose to do that..).

from jellyfin-sdk-kotlin.

Maxr1998 avatar Maxr1998 commented on May 20, 2024

You could import the extension function, or only support the extension functions (aka syntactic sugar) for consumers of the API. Also, if I'm not mistaken, reified actually means simply passing the class to the function as a parameter, hidden behind compiler magic.

from jellyfin-sdk-kotlin.

nielsvanvelzen avatar nielsvanvelzen commented on May 20, 2024

I get your point but the problem is that Ktor doesn't support passing the class as a parameter. It requires a reified type send via generic (https://ktor.io/docs/response.html) but interfaces do not support it.

from jellyfin-sdk-kotlin.

nielsvanvelzen avatar nielsvanvelzen commented on May 20, 2024

I'm thinking we might want to switch from Ktor to something more low-level (like okhttp). This would give us more control and reduce the libraries dependencies. Besides, we don't use most of the Ktor stuff. The biggest change would be to do the JSON serialization ourselves (using kotlinx of course).

from jellyfin-sdk-kotlin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.