Micronaut 可选的枚举查询参数

问题描述

我正在编写 Micronaut 应用程序,但在编写能够采用枚举类型的可选参数的控制器时遇到了问题。问题是,当我添加具有枚举类型的可为空的 @QueryValue 时,每次我尝试点击端点时,它都会返回 403,我认为这是因为我启用了 Micronaut 安全性,它为任何 URL 返回 403未映射。

@Get("/api/contents{?paginationParameter*,state}")
fun findContents(
    @Valid @QueryValue paginationParameter: PaginationParameter,@QueryValue state: ContentState?
): HttpResponse<Unit> {

    return HttpResponse.noContent()
}

我不得不求助于更改 state 以具有类型 String? 并手动序列化。但我想要的是,如果我的 state 参数不存在于查询中,那么 state 变量将为空,否则它会调用 ContentState.valueOf

我试过 Argument BindingHow to automatically map @DefaultValue to an enum parameter using JAX-RS based Restlet?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)