[英]Custom Jersey parameter unmarshalling
我收到類似String的行作為查詢參數
parameter=123,456,789
我想直接在控制器中獲取List<Integer>
。 像這樣:
@GET
@Path(REST_PATH)
@Produces(MediaType.APPLICATION_JSON)
public Response getSomeStuff(@MagicalThing("parameter") List<Integer> requiredList)
除了自定義提供程序和其他類型,可以做什么:
https://stackoverflow.com/a/6124014 ?
更新:自定義注釋解決了難題http://avianey.blogspot.de/2011/12/exception-mapping-jersey.html
沒有內置的機制可以做到這一點。 您將需要在方法或提供程序中,或者在您自己的對象(具有帶字符串參數的構造函數的對象)中自行拆分該字符串,例如:
public Response getSomeStuff(@QueryParam("parameter") MyList requiredList) {
List<String> list = requiredList.getList();
}
MyList可能是:
public class MyList {
List<String> list;
public MyList(Srting parameter) {
list = new ArrayList<String>(parameter.split(","));
}
public List<String> getList() {
return list;
}
}
然后在您的方法中獲取我的列表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.