@ -380,15 +380,14 @@ To serialize only a subset of the object properties, you can specify a {baeldung
@@ -380,15 +380,14 @@ To serialize only a subset of the object properties, you can specify a {baeldung
[source,java,indent=0,subs="verbatim"]
----
MappingJacksonValue value = new MappingJacksonValue(new User("eric", "7!jd#h23"));
@ -255,5 +255,3 @@ For Kotlin `Flow`, a `Flow<T>.transactional` extension is provided.
@@ -255,5 +255,3 @@ For Kotlin `Flow`, a `Flow<T>.transactional` extension is provided.
@ -296,17 +296,17 @@ for example when writing a `org.springframework.core.convert.converter.Converter
@@ -296,17 +296,17 @@ for example when writing a `org.springframework.core.convert.converter.Converter
[source,kotlin,indent=0]
----
class ListOfFooConverter : Converter<List<Foo>, CustomJavaList<out Foo>> {
class ListOfFooConverter : Converter<List<Foo>, CustomJavaList<out Foo>> {
// ...
}
}
----
When converting any kind of objects, star projection with `*` can be used instead of `out Any`.
[source,kotlin,indent=0]
----
class ListOfAnyConverter : Converter<List<*>, CustomJavaList<*>> {
class ListOfAnyConverter : Converter<List<*>, CustomJavaList<*>> {
// ...
}
}
----
NOTE: Spring Framework does not leverage yet declaration-site variance type information for injecting beans,
@ -340,13 +340,14 @@ file with a `spring.test.constructor.autowire.mode = all` property.
@@ -340,13 +340,14 @@ file with a `spring.test.constructor.autowire.mode = all` property.
[source,kotlin,indent=0]
----
@SpringJUnitConfig(TestConfig::class)
@TestConstructor(autowireMode = AutowireMode.ALL)
class OrderServiceIntegrationTests(val orderService: OrderService,
@SpringJUnitConfig(TestConfig::class)
@TestConstructor(autowireMode = AutowireMode.ALL)
class OrderServiceIntegrationTests(
val orderService: OrderService,
val customerService: CustomerService) {
// tests that use the injected OrderService and CustomerService
}
}
----
@ -403,11 +404,12 @@ The following example shows how to do so:
@@ -403,11 +404,12 @@ The following example shows how to do so:
[source,kotlin,indent=0]
----
class SpecificationLikeTests {
class SpecificationLikeTests {
@Nested
@DisplayName("a calculator")
inner class Calculator {
val calculator = SampleCalculator()
@Test
@ -422,7 +424,7 @@ class SpecificationLikeTests {
@@ -422,7 +424,7 @@ class SpecificationLikeTests {
@ -16,8 +14,8 @@ These DSL let you write clean and idiomatic Kotlin code to build a `RouterFuncti
@@ -16,8 +14,8 @@ These DSL let you write clean and idiomatic Kotlin code to build a `RouterFuncti
[source,kotlin,indent=0]
----
@Configuration
class RouterRouterConfiguration {
@Configuration
class RouterRouterConfiguration {
@Bean
fun mainRouter(userHandler: UserHandler) = router {
@ -36,7 +34,7 @@ class RouterRouterConfiguration {
@@ -36,7 +34,7 @@ class RouterRouterConfiguration {
}
resources("/**", ClassPathResource("static/"))
}
}
}
----
NOTE: This DSL is programmatic, meaning that it allows custom registration logic of beans
@ -55,22 +53,22 @@ idiomatic Kotlin API and to allow better discoverability (no usage of static met
@@ -55,22 +53,22 @@ idiomatic Kotlin API and to allow better discoverability (no usage of static met
@ -89,9 +87,9 @@ is possible to use such feature to render Kotlin-based templates with
@@ -89,9 +87,9 @@ is possible to use such feature to render Kotlin-based templates with
Configuration is usually done with `ScriptTemplateConfigurer` and `ScriptTemplateViewResolver` beans.
@ -99,8 +97,8 @@ Configuration is usually done with `ScriptTemplateConfigurer` and `ScriptTemplat
@@ -99,8 +97,8 @@ Configuration is usually done with `ScriptTemplateConfigurer` and `ScriptTemplat
`KotlinScriptConfiguration.kt`
[source,kotlin,indent=0]
----
@Configuration
class KotlinScriptConfiguration {
@Configuration
class KotlinScriptConfiguration {
@Bean
fun kotlinScriptConfigurer() = ScriptTemplateConfigurer().apply {
@ -115,7 +113,7 @@ class KotlinScriptConfiguration {
@@ -115,7 +113,7 @@ class KotlinScriptConfiguration {
setPrefix("templates/")
setSuffix(".kts")
}
}
}
----
See the https://github.com/sdeleuze/kotlin-script-templating[kotlin-script-templating] example
@ -127,7 +125,7 @@ project for more details.
@@ -127,7 +125,7 @@ project for more details.
== Kotlin multiplatform serialization
{kotlin-github-org}/kotlinx.serialization[Kotlin multiplatform serialization] is
supported in Spring MVC, Spring WebFlux and Spring Messaging (RSocket). The builtin support currently targets CBOR, JSON, and ProtoBuf formats.
supported in Spring MVC, Spring WebFlux and Spring Messaging (RSocket). The built-in support currently targets CBOR, JSON, and ProtoBuf formats.
To enable it, follow {kotlin-github-org}/kotlinx.serialization#setup[those instructions] to add the related dependency and plugin.
With Spring MVC and WebFlux, both Kotlin serialization and Jackson will be configured by default if they are in the classpath since
@ -135,6 +133,3 @@ Kotlin serialization is designed to serialize only Kotlin classes annotated with
@@ -135,6 +133,3 @@ Kotlin serialization is designed to serialize only Kotlin classes annotated with
With Spring Messaging (RSocket), make sure that neither Jackson, GSON or JSONB are in the classpath if you want automatic configuration,
if Jackson is needed configure `KotlinSerializationJsonMessageConverter` manually.
public class MultipartExchangeFilterFunction implements ExchangeFilterFunction {
public class MultipartExchangeFilterFunction implements ExchangeFilterFunction {
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
@ -186,14 +186,14 @@ public class MultipartExchangeFilterFunction implements ExchangeFilterFunction {
@@ -186,14 +186,14 @@ public class MultipartExchangeFilterFunction implements ExchangeFilterFunction {
});
}
}
}
}
----
Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
class MultipartExchangeFilterFunction : ExchangeFilterFunction {
class MultipartExchangeFilterFunction : ExchangeFilterFunction {
override fun filter(request: ClientRequest, next: ExchangeFunction): Mono<ClientResponse> {
return if (MediaType.MULTIPART_FORM_DATA.includes(request.headers().getContentType())
@ -217,6 +217,6 @@ class MultipartExchangeFilterFunction : ExchangeFilterFunction {
@@ -217,6 +217,6 @@ class MultipartExchangeFilterFunction : ExchangeFilterFunction {