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

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

View File

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