0

I'm having a weird problem with a Spring MVC. I have a Controller method that accepts 2 date parameters as request parameters startDate and endDate. If I use a simple url with the 2 params like so :

http://localhost/myapp/videos?startDate=2013-05-10&endDate=2013-06-01.json

I get this error message :

[#|2013-05-27T17:39:01.711+0200|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|38386 [http-thread-pool-8080(5)] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver  - Resolving exception from handler [public java.util.List<Video> com.ufasoli.Videos.programs(com.ufasoli.filtering.SearchParams)]: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'searchParams' on field 'endDate': rejected value [2013-06-01.json]; codes [typeMismatch.searchParams.endDate,typeMismatch.endDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [searchParams.endDate,endDate]; arguments []; default message [endDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.format.annotation.DateTimeFormat java.util.Date for value '2013-06-01.json'; nested exception is java.lang.IllegalArgumentException: Invalid format: "2013-06-01.json" is malformed at ".json"]
|#]

But as soon as I remove the .json like so :

http://localhost/myapp/videos?startDate=2013-05-10&endDate=2013-06-01

it all works fine...

This looks like a bug to me as the databinder should not take the url extension into account when binding the data to the controller or is this normal behavior?

Below is the controller method causing the problem :

 @RequestMapping(value = "/videos/", 
                 method = RequestMethod.GET, 
                 produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Videos> videos( SearchParams searchParams) {

        return videosRepository.videos(searchParams);
    }

Here is my SearchParams class :

public class SearchParams extends BaseSearchParams implements Serializable{


    private static final long serialVersionUID = 1L;
    @DateTimeFormat(iso = ISO.DATE, pattern = "yyyy-MM-dd")
    private Date startDate;
    @DateTimeFormat(iso = ISO.DATE, pattern = "yyyy-MM-dd")
    private Date endDate;

     //Setters/Getters
}

I'm using Spring MVC 3.2.1.RELEASE

Any insight?

Thanks in advance

3
  • 3
    I think that the 'url extension' (if any) should be part of the path and belongs therefore before the query: http://localhost/myapp/videos.json?startDate=2013-05-10&endDate=2013-06-01. Commented May 27, 2013 at 16:12
  • Oh god i'm so stupid of course the extension id part of the url. I got it confused with path variables Thanks for pointing it out.. Commented May 27, 2013 at 18:31
  • I posted my comment as answer so you may mark your question as solved. Commented May 27, 2013 at 20:14

1 Answer 1

2

I think that the 'url extension' (if any) should be part of the path and belongs therefore before the query: http://localhost/myapp/videos.json?startDate=2013-05-10&endDate=2013-06-01.

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

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.