Jersey : Is it possible to specify multiple values in @DefaultValue() annotation

丶灬走出姿态 提交于 2019-12-20 03:28:12

问题


I am playing around with Java API for RESTful Web Services (JAX-RS) , and encountered @DefaultValue annotation in Jersey implementation of JAX-RS.

Here is the code snippet

@GET
@Path("/query")
public Response getUserWithQueryParams(
    @DefaultValue("defaultId") @QueryParam("from")String from,
    @DefaultValue("defaultName") @QueryParam("to") String to,
    @DefaultValue("mobileNo")@QueryParam("orderBy") List<String> orderBy
                                        ){

My third argument is of List<String> which can have multiple values

for example I explicitly pass the parameters

users/query?from=100&to=200&orderBy=age&orderBy=name

Now my third argument have values [age,name] ,

but if i don't pass any explicitly parameter then Is there any way to set multiple default values . ?


回答1:


This won't work how you want it to. If the object is type List it will have a single value inserted in the list. The object in the list will be the value of your default value for the list. Check this out Why not try checking if orderBy == null if it does then add your default values to orderBy?



来源:https://stackoverflow.com/questions/29651066/jersey-is-it-possible-to-specify-multiple-values-in-defaultvalue-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!