Json Spring RESTful日期格式

Json Spring RESTful日期格式,json,spring,rest,jackson,Json,Spring,Rest,Jackson,jdk8中的rest控制器如下 @Transactional @RequestMapping(value="/A", method = RequestMethod.POST) public ABean aInsert(final java.sql.Date when, final long company) { A bean = new A(); bean.setWhen(when); bean.setCompany(entityManager.find(Company.class,

jdk8中的rest控制器如下

@Transactional
@RequestMapping(value="/A", method = RequestMethod.POST)
public ABean aInsert(final java.sql.Date when, final long company) {
  A bean = new A();
  bean.setWhen(when);
  bean.setCompany(entityManager.find(Company.class, company));
  entityManager.persist(bean);
  return new ABean(bean.getId(), bean.getVersion(), bean.getWhen(), bean.getCompany().getId());
}
使用表单post数据调用

when=1459987200000&company=1
但无法调用并返回
400-错误请求
(说明客户端发送的请求在语法上不正确。)

我的问题是:

  • java.sql.date
    的默认输入字符串格式是什么

    • 当=2016-04-21&company=10起作用时,其

      yyyy-mm-dd
      
      对于每种其他格式,请按如下方式注册一个自定义项:

      @Autowired
      private final ConfigurableConversionService conversionService=null;
      
      @PostConstruct
      public void registerConverter() {
          conversionService.addConverter(new Converter<String, Long>() {
              @Override
              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);
                  }
              }
          });
      }
      
      @Autowired
      private final ConfigurableConversionService conversionService=null;
      @施工后
      公共无效注册表转换程序(){
      conversionService.addConverter(新转换器(){
      @凌驾
      公共长转换(字符串源){
      试一试{
      SimpleDataFormat df=新的SimpleDataFormat(“yyyy-mm-dd'hh:mm”);
      返回df.parse(source.getTime();
      }捕获(解析异常){
      返回Long.parseLong(源);
      }
      }
      });
      }