I am designing a REST API using JAX-RS. The endpoint looks like the following:
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response get(
@QueryParam("param1") final String param1,
@QueryParam("param2") final String param2) {
// Code goes here
}
I have nearly 7-8 parameters. So I would like to do something like the following:
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response get(@Context MyContextObject context) {
// Code goes here
}
And I have the context object as follows:
final class MyContextObject {
// get methods
public MyContextObject(final Builder builder) {
// set final fields
}
private final String param1;
private final String param2;
public static final class Builder {
// builder code goes here
}
}
Can you please advise how I can do that?
Thanks in advance.