Reputation: 916
For example, I have class
class MyQuery {
Date start;
Date end;
ChronoUnit scale; // ChronoUnit is enum
}
I want to declare method like:
@Path("/myreport")
public Response generateReport(@EntityFromQuery MyQuery query) {
// logic to generate.
}
and I want that this method will be invoked when something is hitting url
/myreport?start=2015-01-01&end=2015-01-31&scale=WEEKS
I'm using Jersey. Is there any internal tool to achieve this? Or I need to write my own MessageBodyReader?
Upvotes: 1
Views: 84
Reputation: 1600
You can take a look at the @BeanParam
annotation that you would use instead of @EntityFromQuery
in the Java method of your JAX-RS Resouce.
In your MyQuery
class, you just need to annotate the getters with @QueryParam("start")
, etc.
See https://jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/javax/ws/rs/BeanParam.html
HTH.
Upvotes: 2
Reputation: 762
That comes out of the box with jersey (you might want to check some tutorials first..). It might be easier for you to accept all GET-Parameters of your incoming requests as Strings and convert them later on:
@GET
@Path("/myreport")
@Produces(MediaType.{whatever you want to return})
public Response generateReport(@QueryParam("start") String start, @QueryParam ("end") String end, @QueryParam ("scale") String scale) {
// convert from string to date and from string to chroneUnit
//do some logic..
}
Upvotes: 0