users@jersey.java.net

[Jersey] Re: Date parameter in the url

From: Arul Dhesiaseelan <aruld_at_acm.org>
Date: Mon, 20 Jun 2011 16:13:46 -0600

It is very easy to implement this approach for java.util.Date. You can
adjust the SDF based on your req.

public class DateParam extends AbstractParam<Date> {
  //Mon Jun 13 11:10:30 MDT 2011 => EEE MMM d HH:mm:ss z yyyy
  private static final SimpleDateFormat SDF = new SimpleDateFormat("EEE MMM
d HH:mm:ss z yyyy");

  public DateParam(String param) throws WebApplicationException {
    super(param);
  }

  @Override
  protected Date parse(String param) throws Throwable {
    return SDF.parse(param);
  }
}

-Arul

On Mon, Jun 20, 2011 at 4:06 PM, Arul Dhesiaseelan <aruld_at_acm.org> wrote:

> I believe you wanted to do something like this.
>
> http://codahale.com/what-makes-jersey-interesting-parameter-classes/
>
> This is an excellent post, btw.
>
> -Arul
>
>
> On Thu, Jun 16, 2011 at 8:40 PM, jiangc1987 <jiangcheng198745_at_sina.com>wrote:
>
>> Hi all
>> I have a question about the date param in the URL, I wan't to transfer
>> the
>> user into java.util.date automatic
>>
>> for example; I have a request with the URL as below
>>
>> .../date/2011%06%17
>>
>> in the resource i receive this param with
>>
>> @path("/date/{date}")
>> @Produces("text/plain")
>> public String getDate(@pathParm("date")Date date){
>> .......
>> }
>> How does jersey solution on this?
>> Thanks
>> ChengJiang
>>
>> -----
>> name:Joyce
>> Email:jiangcheng198745_at_sina.com
>> address: hangzhou city, zhejiang province, china
>> --
>> View this message in context:
>> http://jersey.576304.n2.nabble.com/Date-parameter-in-the-url-tp6485543p6485543.html
>> Sent from the Jersey mailing list archive at Nabble.com.
>>
>
>
>