英文:
how to convert enum request in kotlin?
问题
我正在使用带有 Spring 的 Kotlin。我想要转换来自前端的请求。我的枚举类是:
enum class Type() {
PARTIAL,
FULL;
fun equal(type: String) {
return this.equal(type.toUpperCase())
}
}
我的获取 API 请求如下:
fun updateUserInfo(user: User, @Valid @RequestBody request: RequestBody) {...}
我的请求体如下:
class RequestBody private constructor() {
@NotNull
lateinit var type: Type
@NotBlank
@Size(max = 40)
lateinit var fullName: String
}
我的问题是,前端可能会使用小写,比如 partial,full
。我希望无论前端发送什么,我的 Type 枚举在 updateUserInfo 函数中始终以大写形式呈现。我该如何做到这一点?
英文:
I am using Kotlin with spring. I want to convert request which comes from the front end. My enum class is:
enum class Type() {
PARTIAL,
FULL;
fun equal(type:String){
return this.equal(type.toUpperCase())
}
}
My get api request is like this
fun updateUserInfo(user: User, @Valid @RequestBody request: RequestBody) {...}
My Request body is like this:
class RequestBody private constructor() {
@NotNull
lateinit var type: Type
@NotBlank
@Size(max = 40)
lateinit var fullName: String
}
My question is this frontend might using small casing like partial,full
. I want to add modifier irrespective of anything frontend send my Type enum should always give an upper case in updateUserInfo function. How can I do it?
专注分享java语言的经验与见解,让所有开发者获益!
评论