Reputation: 87
I have a rest service which validates date now i need to modify it to take two dates, but i don't know if to use @PathParam
or @QueryParam
and if i can insert it between two @PathParam
This it the original code :
@Path("isDateValid/{date}/{itemId}")
public boolean isDateValid(@PathParam("date") Date date, @PathParam("itemId") Long itemId) {
Should i do like this :
@Path("isDateValid/{startDate}/{endDate}/{itemId}")
public boolean isDateValid(@PathParam("startDate") Date startDate, @PathParam("endDate") Date endDate, @PathParam("itemId") Long itemId) {
Upvotes: 1
Views: 4619
Reputation: 148
If you do not want to use third party stuff, I suggest you define a format for the text-date. You can use the SimpleDateFormat class (avoid the space). The you can use the following code.
@Path("isDateValid/{itemId}")
public boolean isDateValid(@PathParam("itemId") Long itemId) {
@QueryParam("begin") String sBegin;
@QueryParam("end") String sEnd;
SimpleDateFormat sdf = new SimpleDateFormat(/* Your patern, for example "yyMMddHHmmssZ"*/);
Date dBegin = sdf.parse(sBegin);
Date dEnd = sdf.parse(sEnd);
/*
...
*/
}
Upvotes: 1
Reputation: 1878
Date Class is cannot serialize using JAX-RS as it is not a simple type. You need to develop the same using MessageBodyReader/Writer . Click Here for more
Or you can use some third party stuff to configure to get it done.
Click Here for more
Upvotes: 1