com.fasterxml.jackson.databind.exc.invalidformatexception:无法从字符串中估算类型的值:不是enum class接受的值之一
我正在将Spring Boot 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]
sepentype
是枚举类别:
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后,当挑战失败?
I'm upgrading a Spring Boot web service from Kotlin 1.4.32
to 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"
After upgrading and running the API, I get the following error:
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
is an enum 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
}
}
Why does deserialization fail after upgrading Kotlin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过升级到 Kotlin
1.6.x
解决了这个问题。I was able to resolve this issue by upgrading to Kotlin
1.6.x
.