Skip to content

Commit

Permalink
Make @Separator work with @BeanParam as well
Browse files Browse the repository at this point in the history
Follows up on: quarkusio#29550
  • Loading branch information
geoand committed Dec 7, 2022
1 parent 841d750 commit 2b83f06
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.List;

import javax.ws.rs.BeanParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

Expand Down Expand Up @@ -32,6 +33,15 @@ public void noQueryParams() {
.header("x-size", "0");
}

@Test
public void noQueryParamsBean() {
get("/hello/bean")
.then()
.statusCode(200)
.body(Matchers.equalTo("hello world"))
.header("x-size", "0");
}

@Test
public void singleQueryParam() {
get("/hello?name=foo")
Expand All @@ -41,6 +51,15 @@ public void singleQueryParam() {
.header("x-size", "1");
}

@Test
public void singleQueryParamBean() {
get("/hello/bean?name=foo")
.then()
.statusCode(200)
.body(Matchers.equalTo("hello foo"))
.header("x-size", "1");
}

@Test
public void multipleQueryParams() {
get("/hello?name=foo,bar&name=one,two,three&name=yolo")
Expand All @@ -55,6 +74,16 @@ public static class HelloResource {

@GET
public RestResponse<String> hello(@RestQuery("name") @Separator(",") List<String> names) {
return toResponse(names);
}

@GET
@Path("bean")
public RestResponse<String> helloBean(@BeanParam Bean bean) {
return toResponse(bean.names);
}

private RestResponse<String> toResponse(List<String> names) {
int size = names.size();
String body = "";
if (names.isEmpty()) {
Expand All @@ -66,4 +95,10 @@ public RestResponse<String> hello(@RestQuery("name") @Separator(",") List<String
}

}

public static class Bean {
@RestQuery("name")
@Separator(",")
public List<String> names;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* parameter (using the value of the annotation) and populate the list with those values.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.PARAMETER })
@Target({ ElementType.PARAMETER, ElementType.FIELD })
public @interface Separator {

String value();
Expand Down

0 comments on commit 2b83f06

Please sign in to comment.