Anyone here have any suggestions for an equivalent...
# ktor
j
Anyone here have any suggestions for an equivalent in the Kotlin reflection library so I don't need a dependency upon apache commons 3.
👀 1
e
Could you provide some use cases of
returnTypeInfo
method? It could be possible with reified parameters
j
@e5l I'm trying to add support for generating swagger schemas using reflection. https://github.com/JLLeitschuh/ktor-swagger/pull/1 This is an example usage:
Copy code
class GenericSubModel<S>(val value: S)
    class ModelWithNestedGeneric<T>(val subModelElement: GenericSubModel<T>)

    @Test
    fun `generic type extraction`() {
        val typeInfo = typeInfo<ModelWithNestedGeneric<String>>()

        val property = ModelWithNestedGeneric::class.memberProperties.first()

        val typeInfoForProperty = typeInfo<GenericSubModel<String>>()

        assertEqualTypeInfo(typeInfoForProperty, property.returnTypeInfo(typeInfo.reifiedType))
    }
e
There is no way to do it in kotlin for now. You have to build proper java
Type
using java reflection
j
@e5l I was hoping that I could avoid having to create my my own custom implementation of
ParameterizedType
. I'm also not a huge fan of having a dependency upon apache commons. I'd really love to have this project eventually get integrated into Ktor proper and I don't think that will happen with an external dependency upon apache commons 3. Still looking for feedback on this proposal: https://github.com/ktorio/ktor/issues/453