kotlin-spring: fix exception thrown in enum.forValue (#21622)

* kotlin-spring: fix exception thrown in enum.forValue

* update samples
This commit is contained in:
Stefan Wurzinger
2025-07-28 10:01:03 +02:00
committed by GitHub
parent ee5a12a29d
commit 0e97e19bbc
35 changed files with 70 additions and 35 deletions

View File

@@ -41,7 +41,8 @@ data class ApiError(
@JvmStatic
@JsonCreator
fun forValue(value: kotlin.Int): ErrorCode {
return values().first{it -> it.value == value}
return values().firstOrNull{it -> it.value == value}
?: throw IllegalArgumentException("Unexpected value '$value' for enum 'ApiError'")
}
}
}

View File

@@ -27,7 +27,8 @@ enum class ReasonCode(@get:JsonValue val value: kotlin.Int) {
@JvmStatic
@JsonCreator
fun forValue(value: kotlin.Int): ReasonCode {
return values().first{it -> it.value == value}
return values().firstOrNull{it -> it.value == value}
?: throw IllegalArgumentException("Unexpected value '$value' for enum 'ReasonCode'")
}
}
}