加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Spring Boot没有使用Jackson Kotlin插件

发布时间:2020-12-15 01:47:06 所属栏目:大数据 来源:网络整理
导读:我不能强迫Spring为Jackson使用Kotlin模块. 问题是Jackson无法将JSON解析为数据类. //Exception2018-02-23 13:29:09.046 ERROR 24730 --- [nio-9300-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in c

我不能强迫Spring为Jackson使用Kotlin模块.
问题是Jackson无法将JSON解析为数据类.

//Exception
2018-02-23 13:29:09.046 ERROR 24730 --- [nio-9300-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/services] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [*.model.User]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Parameter specified as non-null is null: method *.model.User.

我试图配置杰克逊,但它没有多大帮助.有什么奇怪的,在我配置ObjectMapper的@Bean方法中,一切正常.
此外,当我为非可空字段添加默认值时,它们不会被覆盖.

@Configuration
class JacksonConfig {
    @Bean
    fun mappingJackson2HttpMessageConverter(): MappingJackson2HttpMessageConverter {
        val mapper = ObjectMapper().registerKotlinModule()
        mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false)
        var user = mapper.readValue

可能重要的是模型与应用程序本身在不同的项目中.

Kotlin版本是1.20
杰克逊依赖:

    

我现在尝试的是:

All of these answers

Similiar problem but probably different case anyway

还有一些其他的,不值得注意的.

最佳答案
我是愚蠢的,认真的.

我的结构如下:

abstract class AbstractController (...) {
    fun save(@RequestMapping entity: T) {
    (...)
}

并启用它我用过

class DeriveredController (...) {
    @PostMapping
    override fun save(entity: Derivered) {
    (...)
    }
}

问题在于导出函数中缺少@RequestMapping.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读