Issue
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?
Solution
I was able to resolve this issue by upgrading to Kotlin 1.6.x
.
Answered By - Ryan Payne
Answer Checked By - Senaida (JavaFixing Volunteer)