Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:13:30+00:00 2026-06-18T16:13:30+00:00

I have a REST API that optionally supports two querystring parameters: starttime and endtime

  • 0

I have a REST API that optionally supports two querystring parameters: starttime and endtime, both self-explanatory.

Currently I pass the WebRequest parameter to my controller API and search for the timestamp (encoded as Long), then convert it to Calendar.

I wonder if there is a way to have the Calendar parameters automatically passed to API without going with processing queryString. Something like

public Object[] myApi([...], Calendar startTime, Calendar endTime)

Most importantly, the parameters must both be optional (any can be specified or be null)

How can I do that in Spring MVC?

Example of current code:

@RequestMapping(value = "/rest/{datatype}", method = RequestMethod.GET, produces = { "application/json" })
public @ResponseBody
Object[] getData(@PathVariable("datatype") String dataType,
        WebRequest request) throws HttpException {
    if (dataType == null || "".equals(dataType))
        throw new ClientException("Datatype cannot be empty");

    Calendar timestampInit = null;
    if (request.getParameter(PARAMETER_STARTTIME) != null) {
        try {
            timestampInit = Calendar.getInstance();
            timestampInit.setTimeInMillis(Long.valueOf(request
                    .getParameter(PARAMETER_STARTTIME)));
        } catch (NumberFormatException ex) {
            throw new ClientException("Invalid start time", ex);
        }
    }

    Calendar timestampEnd = null;
    if (request.getParameter(PARAMETER_ENDTIME) != null) {
        try {
            timestampEnd = Calendar.getInstance();
            timestampEnd.setTimeInMillis(Long.valueOf(request
                    .getParameter(PARAMETER_ENDTIME)));
        } catch (NumberFormatException ex) {
            throw new ClientException("Invalid end time", ex);
        }
    }
            [...]
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:13:31+00:00Added an answer on June 18, 2026 at 4:13 pm

    Take a look at StringParamUnmarshaller
    http://docs.jboss.org/resteasy/2.0.0.GA/userguide/html/StringConverter.html
    usually most of REST frameworks are +- same so i believe there should be something same in your configuration

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a REST API that must be authenticated via BasicAuth, but later
Say I have a REST API in java, and it supports responses that are
I'm developing a REST api. To simplify my question, I have an API that
I'm testing my REST API and the issue i have is that i create
We have a REST API where clients can supply parameters representing values defined on
We have a REST API that works great. We're refactoring and deciding how to
I have some tests of a REST API service that I've written in Scala.
I have a REST service that is exposed to iPhone and Android clients. Currently
I have a REST API that returns json responses. Sometimes (and what seems to
I have a REST-ish API that returns JSON. One of the output fields is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.