com.fasterxml.jackson.databind.exc.InvalidFormatException: 无法反序列化 String 类型的值:不是 Enum class 接受的值之一

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type from String: not one of the values accepted for Enum class

我正在将 Spring 引导 Web 服务从 Kotlin 1.4.32 升级到 1.5.0

// Before:
kotlin("jvm") version "1.4.32"
kotlin("plugin.spring") version "1.4.32"

// After:
kotlin("jvm") version "1.5.0"
kotlin("plugin.spring") version "1.5.0"

升级 运行 API 后,出现以下错误:

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `models.SeasonType` from String "Season": not one of the values accepted for Enum class: [NO_SEASON, UNKNOWN, SEASON]

SeasonType 是一个枚举 class:

package models

import com.fasterxml.jackson.annotation.JsonCreator

enum class SeasonType(val value: String) {

    SEASON("Season"),
    NO_SEASON("NoSeason"),
    UNKNOWN("Unknown");

    companion object {
        @JsonCreator
        @JvmStatic
        private fun creator(serializedValue: String): SeasonType =
            values().firstOrNull { it.value == serializedValue } ?: UNKNOWN
    }

}

为什么升级Kotlin后反序列化失败?

我通过升级到 Kotlin 1.6.x 解决了这个问题。