GH-1260 Additional fix to Kotlin type resolution for generics

This is specifically relevant to the way Kotlin represents types. For example List<Message> resolves to List <? extends Message> which becomes the WildCard unlike in Java

Resolves #1260
This commit is contained in:
Oleg Zhurakousky
2025-04-11 12:26:00 +02:00
parent 5c31eace74
commit 7fc81cab28
3 changed files with 75 additions and 5 deletions

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2019-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.kotlin;
import java.lang.reflect.Type;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.function.context.catalog.FunctionTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
public class KotlinTypeDiscoveryTests {
@Test
public void testOutputInputTypes() {
Type functionType = FunctionTypeUtils.discoverFunctionTypeFromClass(KotlinComponentMessageFunction.class);
Type outputType = FunctionTypeUtils.getOutputType(functionType);
assertThat(FunctionTypeUtils.isMessage(outputType)).isTrue();
Type inputType = FunctionTypeUtils.getInputType(functionType);
assertThat(FunctionTypeUtils.isMessage(inputType)).isTrue();
}
}

View File

@@ -0,0 +1,15 @@
package org.springframework.cloud.function.kotlin
import org.springframework.messaging.Message
import org.springframework.messaging.MessageHeaders
import org.springframework.messaging.support.MessageBuilder
import org.springframework.stereotype.Component
import java.util.function.Function
@Component
class KotlinComponentMessageFunction : (List<Message<Char>>) -> List<Message<Char>> {
override fun invoke(input: List<Message<Char>>): List<Message<Char>> {
return input
}
}