fix(json): применять Kotlin-модуль Jackson 3
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.ysu.lms.academic.config
|
||||||
|
|
||||||
|
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import tools.jackson.module.kotlin.KotlinModule
|
||||||
|
|
||||||
|
/** Jackson 3: без Kotlin-модуля DTO с default-значениями требуют все поля JSON. */
|
||||||
|
@Configuration
|
||||||
|
class JacksonConfig {
|
||||||
|
@Bean
|
||||||
|
fun kotlinModule(): KotlinModule = KotlinModule.Builder().build()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun kotlinJsonCustomizer(): JsonMapperBuilderCustomizer =
|
||||||
|
JsonMapperBuilderCustomizer { builder -> builder.addModule(KotlinModule.Builder().build()) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package ru.ysu.lms.identity.config
|
||||||
|
|
||||||
|
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import tools.jackson.module.kotlin.KotlinModule
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson 3 не подхватывает Kotlin-модуль автоматически в Spring Boot 4:
|
||||||
|
* без него DTO с default-значениями требуют все поля в JSON.
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
class JacksonConfig {
|
||||||
|
@Bean
|
||||||
|
fun kotlinModule(): KotlinModule = KotlinModule.Builder().build()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun kotlinJsonCustomizer(): JsonMapperBuilderCustomizer =
|
||||||
|
JsonMapperBuilderCustomizer { builder -> builder.addModule(KotlinModule.Builder().build()) }
|
||||||
|
}
|
||||||
@@ -65,6 +65,8 @@ class TeacherIntegrationTest {
|
|||||||
|
|
||||||
@Autowired lateinit var context: WebApplicationContext
|
@Autowired lateinit var context: WebApplicationContext
|
||||||
|
|
||||||
|
@Autowired lateinit var jsonMapper: tools.jackson.databind.json.JsonMapper
|
||||||
|
|
||||||
private val mockMvc: MockMvc by lazy {
|
private val mockMvc: MockMvc by lazy {
|
||||||
MockMvcBuilders
|
MockMvcBuilders
|
||||||
.webAppContextSetup(context)
|
.webAppContextSetup(context)
|
||||||
@@ -184,6 +186,19 @@ class TeacherIntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `student creation accepts omitted optional json fields`() {
|
||||||
|
val request =
|
||||||
|
jsonMapper.readValue(
|
||||||
|
"""{"studentNo":"api-student-1","lastName":"Тестов"}""",
|
||||||
|
CreateStudentRequest::class.java,
|
||||||
|
)
|
||||||
|
assertEquals("api-student-1", request.studentNo)
|
||||||
|
assertEquals("Тестов", request.lastName)
|
||||||
|
assertEquals("", request.firstName)
|
||||||
|
assertEquals("", request.basis)
|
||||||
|
}
|
||||||
|
|
||||||
private fun student(login: String): Account =
|
private fun student(login: String): Account =
|
||||||
Account(
|
Account(
|
||||||
login = login,
|
login = login,
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.ysu.lms.progress.config
|
||||||
|
|
||||||
|
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import tools.jackson.module.kotlin.KotlinModule
|
||||||
|
|
||||||
|
/** Jackson 3: без Kotlin-модуля DTO с default-значениями требуют все поля JSON. */
|
||||||
|
@Configuration
|
||||||
|
class JacksonConfig {
|
||||||
|
@Bean
|
||||||
|
fun kotlinModule(): KotlinModule = KotlinModule.Builder().build()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun kotlinJsonCustomizer(): JsonMapperBuilderCustomizer =
|
||||||
|
JsonMapperBuilderCustomizer { builder -> builder.addModule(KotlinModule.Builder().build()) }
|
||||||
|
}
|
||||||
17
web/src/main/kotlin/ru/ysu/lms/web/config/JacksonConfig.kt
Normal file
17
web/src/main/kotlin/ru/ysu/lms/web/config/JacksonConfig.kt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.ysu.lms.web.config
|
||||||
|
|
||||||
|
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import tools.jackson.module.kotlin.KotlinModule
|
||||||
|
|
||||||
|
/** Jackson 3: без Kotlin-модуля DTO с default-значениями требуют все поля JSON. */
|
||||||
|
@Configuration
|
||||||
|
class JacksonConfig {
|
||||||
|
@Bean
|
||||||
|
fun kotlinModule(): KotlinModule = KotlinModule.Builder().build()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun kotlinJsonCustomizer(): JsonMapperBuilderCustomizer =
|
||||||
|
JsonMapperBuilderCustomizer { builder -> builder.addModule(KotlinModule.Builder().build()) }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user