Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
@JvmStatic
@JsonCreator
fun forValue(value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}): {{{nameInPascalCase}}} {
return values().first{it -> it.value == value}
return values().firstOrNull{it -> it.value == value}
?: throw IllegalArgumentException("Unexpected value '$value' for enum '{{classname}}'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ enum class {{classname}}(@get:JsonValue val value: {{dataType}}) {
@JvmStatic
@JsonCreator
fun forValue(value: {{dataType}}): {{classname}} {
return values().first{it -> it.value == value}
return values().firstOrNull{it -> it.value == value}
?: throw IllegalArgumentException("Unexpected value '$value' for enum '{{classname}}'")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ data class AnyOfUserOrPet(
@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 'AnyOfUserOrPet'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ data class AnyOfUserOrPetOrArrayString(
@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 'AnyOfUserOrPetOrArrayString'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ data class UserOrPet(
@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 'UserOrPet'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ data class UserOrPetOrArrayString(
@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 'UserOrPetOrArrayString'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ enum class MultipartMixedStatus(@get:JsonValue val value: kotlin.String) {
@JvmStatic
@JsonCreator
fun forValue(value: kotlin.String): MultipartMixedStatus {
return values().first{it -> it.value == value}
return values().firstOrNull{it -> it.value == value}
?: throw IllegalArgumentException("Unexpected value '$value' for enum 'MultipartMixedStatus'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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'")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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'")
}
}
}
Expand Down
Loading