Peter Rader Peter Rader - 1 year ago 92
reST (reStructuredText) Question

Spring RESTful Date format

A rest controller in jdk8 like this

@RequestMapping(value="/A", method = RequestMethod.POST)
public ABean aInsert(final java.sql.Date when, final long company) {
A bean = new A();
bean.setCompany(entityManager.find(Company.class, company));
return new ABean(bean.getId(), bean.getVersion(), bean.getWhen(), bean.getCompany().getId());

is called with form post-data


but can not be called and returns a
400 - bad request
(description The request sent by the client was syntactically incorrect.)

My question is:

  • What is the default input string format of the

Answer Source

when=2016-04-21&company=10 Works, so its


For every other format register a custom Converter like this:

private final ConfigurableConversionService conversionService=null;

public void registerConverter() {
    conversionService.addConverter(new Converter<String, Long>() {
        public Long convert(String source) {
            try {
                SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd'T'hh:mm");
                return df.parse(source).getTime();
            } catch (ParseException e) {
                return Long.parseLong(source);