|
|
|
@ -20,6 +20,8 @@ import kotlinx.serialization.Serializable |
|
|
|
import org.assertj.core.api.Assertions |
|
|
|
import org.assertj.core.api.Assertions |
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import org.springframework.core.MethodParameter |
|
|
|
import org.springframework.core.MethodParameter |
|
|
|
|
|
|
|
import org.springframework.http.RequestEntity |
|
|
|
|
|
|
|
import org.springframework.http.ResponseEntity |
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter |
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter |
|
|
|
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter |
|
|
|
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter |
|
|
|
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean |
|
|
|
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean |
|
|
|
@ -68,6 +70,22 @@ class RequestResponseBodyMethodProcessorKotlinTests { |
|
|
|
.contains("\"value\":\"foo\"") |
|
|
|
.contains("\"value\":\"foo\"") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun writeEntityWithKotlinSerializationJsonMessageConverter() { |
|
|
|
|
|
|
|
val method = SampleController::writeMessageEntity::javaMethod.get()!! |
|
|
|
|
|
|
|
val handlerMethod = HandlerMethod(SampleController(), method) |
|
|
|
|
|
|
|
val methodReturnType = handlerMethod.returnType |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val converters = listOf(KotlinSerializationJsonHttpMessageConverter()) |
|
|
|
|
|
|
|
val processor = RequestResponseBodyMethodProcessor(converters, null, listOf(KotlinResponseBodyAdvice())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val returnValue: Any? = SampleController().writeMessageEntity().body |
|
|
|
|
|
|
|
processor.handleReturnValue(returnValue, methodReturnType, this.container, this.request) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(this.servletResponse.contentAsString) |
|
|
|
|
|
|
|
.contains("\"value\":\"foo\"") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun writeGenericTypeWithKotlinSerializationJsonMessageConverter() { |
|
|
|
fun writeGenericTypeWithKotlinSerializationJsonMessageConverter() { |
|
|
|
val method = SampleController::writeMessages::javaMethod.get()!! |
|
|
|
val method = SampleController::writeMessages::javaMethod.get()!! |
|
|
|
@ -118,6 +136,24 @@ class RequestResponseBodyMethodProcessorKotlinTests { |
|
|
|
Assertions.assertThat(result).isEqualTo(Message("foo")) |
|
|
|
Assertions.assertThat(result).isEqualTo(Message("foo")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
|
|
|
|
fun readEntityWithKotlinSerializationJsonMessageConverter() { |
|
|
|
|
|
|
|
val content = "{\"value\" : \"foo\"}" |
|
|
|
|
|
|
|
this.servletRequest.setContent(content.toByteArray(StandardCharsets.UTF_8)) |
|
|
|
|
|
|
|
this.servletRequest.setContentType("application/json") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val converters = listOf(StringHttpMessageConverter(), KotlinSerializationJsonHttpMessageConverter()) |
|
|
|
|
|
|
|
val processor = RequestResponseBodyMethodProcessor(converters, null, listOf(KotlinRequestBodyAdvice())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val method = SampleController::readMessageEntity::javaMethod.get()!! |
|
|
|
|
|
|
|
val methodParameter = MethodParameter(method, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val result = processor.resolveArgument(methodParameter, container, request, factory) as Message |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(result).isEqualTo(Message("foo")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun readGenericTypeWithKotlinSerializationJsonMessageConverter() { |
|
|
|
fun readGenericTypeWithKotlinSerializationJsonMessageConverter() { |
|
|
|
@ -161,6 +197,10 @@ class RequestResponseBodyMethodProcessorKotlinTests { |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
fun writeMessage() = Message("foo") |
|
|
|
fun writeMessage() = Message("foo") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping |
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
fun writeMessageEntity() = ResponseEntity.ok(Message("foo")) |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping |
|
|
|
@RequestMapping |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
fun writeMessages() = listOf(Message("foo"), Message("bar")) |
|
|
|
fun writeMessages() = listOf(Message("foo"), Message("bar")) |
|
|
|
@ -169,6 +209,10 @@ class RequestResponseBodyMethodProcessorKotlinTests { |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
fun readMessage(message: Message) = message.value |
|
|
|
fun readMessage(message: Message) = message.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping |
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
fun readMessageEntity(entity: RequestEntity<Message>) = entity.body!!.value |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping |
|
|
|
@RequestMapping |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
fun readMessages(messages: List<Message>) = messages.map { it.value }.reduce { acc, string -> "$acc $string" } |
|
|
|
fun readMessages(messages: List<Message>) = messages.map { it.value }.reduce { acc, string -> "$acc $string" } |
|
|
|
|