1

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) {

2 Answers 2

1

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);

/*
...
*/
}
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.