Edit: Just upgrade to Spring Boot 2.5.1 where this is resolved.
Old answer below:
I managed to fix this for now by adding exclusions to my spring-boot-starter-security dependency which apparently defined this Kotlin dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</exclusion>
</exclusions>
</dependency>
Answer from Sebastiaan van den Broek on Stack OverflowEdit: Just upgrade to Spring Boot 2.5.1 where this is resolved.
Old answer below:
I managed to fix this for now by adding exclusions to my spring-boot-starter-security dependency which apparently defined this Kotlin dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</exclusion>
</exclusions>
</dependency>
There seems to be a solution here. The idea is to provide extra configuration for Jackson2ObjectMapperBuilderCustomizer. Sucks that a code change is required but there you have it.
Add @RequestBody to your controller method as
@PostMapping("/login")
fun login (@RequestBody req : AuthorizationRequest): String {
return "received auth request: ${req.username}"
}
Response is:

Can you try this? Since a few Kotlin versions I got the warning that you have to decide where you want to put the annotation on: constructor parameter or the field itself.
data class AuthenticationRequest(
@param:JsonProperty
val username : String,
@param:JsonProperty
val password : String
)
// alternative
data class AuthenticationRequest(
@field:JsonProperty
val username : String,
@field:JsonProperty
val password : String
)
Based on the information you gave, the problem seems to be with using _ as JsonProperty value. You may have observed all your properties for MetaData contain _. Try removing all the underscores and see. I hope also you've registered the ObjectMapper, example in your Application class:
@Bean
open fun objectMapperBuilder(): Jackson2ObjectMapperBuilder
= Jackson2ObjectMapperBuilder().modulesToInstall(KotlinModule())
I had to use the following combination of dependencies
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.7.3</version>
</dependency>
The update form jackson-module-kotlin from 2.7.1-2 to 2.7.3 had little to no diference in the problem, but i was obligated to include the jackson-core, jackson-annotations, and jackson-databind.
Aparently the jackson jar included in the jackson-module-kotlin had some issues spring-webmvc that prevented me from registering the kotlin module as shown below
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper" ref="kotlinMapper" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="kotlinMapper"
class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
<property name="featuresToEnable">
<array>
<util:constant static-field="com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT" />
<util:constant static-field="com.fasterxml.jackson.databind.SerializationFeature.WRITE_EMPTY_JSON_ARRAYS" />
</array>
</property>
<property name="modulesToInstall" value="com.fasterxml.jackson.module.kotlin.KotlinModule" />
</bean>
In the end those _ in the @JsonProperty worked just fine.