{"action":"reopened","issue":{"url":"https://api.github.com/repos/alibaba/fastjson/issues/837","repository_url":"https://api.github.com/repos/alibaba/fastjson","labels_url":"https://api.github.com/repos/alibaba/fastjson/issues/837/labels{/name}","comments_url":"https://api.github.com/repos/alibaba/fastjson/issues/837/comments","events_url":"https://api.github.com/repos/alibaba/fastjson/issues/837/events","html_url":"https://github.com/alibaba/fastjson/issues/837","id":179150396,"number":837,"title":"SpringMVC环境下，JSON反序列化为对象时日期字段出错","user":{"login":"lifeixiang027","id":18546370,"avatar_url":"https://avatars.githubusercontent.com/u/18546370?v=3","gravatar_id":"","url":"https://api.github.com/users/lifeixiang027","html_url":"https://github.com/lifeixiang027","followers_url":"https://api.github.com/users/lifeixiang027/followers","following_url":"https://api.github.com/users/lifeixiang027/following{/other_user}","gists_url":"https://api.github.com/users/lifeixiang027/gists{/gist_id}","starred_url":"https://api.github.com/users/lifeixiang027/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lifeixiang027/subscriptions","organizations_url":"https://api.github.com/users/lifeixiang027/orgs","repos_url":"https://api.github.com/users/lifeixiang027/repos","events_url":"https://api.github.com/users/lifeixiang027/events{/privacy}","received_events_url":"https://api.github.com/users/lifeixiang027/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-26T06:42:04Z","updated_at":"2016-10-14T01:47:19Z","closed_at":null,"body":"1、配置如下：\r\n\r\n\t<bean id=\"fastJsonConfig\" class=\"com.alibaba.fastjson.support.config.FastJsonConfig\">\r\n\t\t<property name=\"charset\" value=\"UTF-8\" />\r\n\t\t<property name=\"dateFormat\" value=\"yyyy/MM/dd HH:mm\" />\r\n\t</bean>\r\n\t<mvc:annotation-driven>\r\n\t\t<mvc:message-converters>\r\n\t\t\t<bean class=\"com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4\">\r\n\t\t\t\t<!-- MediaTypes -->\r\n\t\t\t\t<property name=\"supportedMediaTypes\">\r\n\t\t\t\t\t<list>\r\n\t\t\t\t\t\t<value>application/json</value>\r\n\t\t\t\t\t\t<value>text/xml</value>\r\n\t\t\t\t\t\t<value>text/html</value>\r\n\t\t\t\t\t</list>\r\n\t\t\t\t</property>\r\n\t\t\t\t<!-- FastJsonConfig -->\r\n\t\t\t\t<property name=\"fastJsonConfig\" ref=\"fastJsonConfig\" />\r\n\t\t\t</bean>\r\n\t\t</mvc:message-converters>\r\n\t</mvc:annotation-driven>\r\n\r\n2、错误信息\r\n\r\n> java.lang.NumberFormatException: For input string: \"2016/09/22 16:55\"\r\n\tat java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)\r\n\tat java.lang.Long.parseLong(Long.java:589)\r\n\tat java.lang.Long.parseLong(Long.java:631)\r\n\tat com.alibaba.fastjson.parser.deserializer.SqlDateDeserializer.castTimestamp(SqlDateDeserializer.java:115)\r\n\tat com.alibaba.fastjson.parser.deserializer.SqlDateDeserializer.cast(SqlDateDeserializer.java:31)\r\n\tat com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer.deserialze(AbstractDateDeserializer.java:142)\r\n\tat com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer.deserialze(AbstractDateDeserializer.java:19)\r\n\tat com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:68)\r\n\tat com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:543)\r\n\tat com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:189)\r\n\tat com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:59)\r\n\tat com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:543)\r\n\tat com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:189)\r\n\tat com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:185)\r\n\tat com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:614)\r\n\tat com.alibaba.fastjson.JSON.parseObject(JSON.java:339)\r\n\tat com.alibaba.fastjson.JSON.parseObject(JSON.java:307)\r\n\tat com.alibaba.fastjson.JSON.parseObject(JSON.java:270)\r\n\tat com.alibaba.fastjson.JSON.parseObject(JSON.java:370)\r\n\tat com.alibaba.fastjson.JSON.parseObject(JSON.java:452)\r\n\tat com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4.read(FastJsonHttpMessageConverter4.java:71)\r\n\r\n\r\n3、在Java对象中增加JSONField注解错误一样\r\n\r\n\t@JSONField(format = \"yyyy/MM/dd HH:mm\")\r\n\tprivate Timestamp modifyStamp;\r\n\r\n4、查看FastJsonHttpMessageConverter4源码，FastJsonConfig中配置的dateFormat只影响序列化方法，不影响反序列化方法\r\n\r\n    @Override\r\n    public Object read(Type type, //\r\n                       Class<?> contextClass, //\r\n                       HttpInputMessage inputMessage //\r\n    ) throws IOException, HttpMessageNotReadableException {\r\n        InputStream in = inputMessage.getBody();\r\n        return JSON.parseObject(in, fastJsonConfig.getCharset(), type, fastJsonConfig.getFeatures());\r\n    }\r\n\r\n    @Override\r\n    protected void writeInternal(Object obj, //\r\n                                 Type type, //\r\n                                 HttpOutputMessage outputMessage //\r\n    ) throws IOException, HttpMessageNotWritableException {\r\n\r\n        HttpHeaders headers = outputMessage.getHeaders();\r\n        ByteArrayOutputStream outnew = new ByteArrayOutputStream();\r\n        int len = JSON.writeJSONString(outnew, //\r\n                fastJsonConfig.getCharset(), //\r\n                obj, //\r\n                fastJsonConfig.getSerializeConfig(), //\r\n                fastJsonConfig.getSerializeFilters(), //\r\n                fastJsonConfig.getDateFormat(), //\r\n                JSON.DEFAULT_GENERATE_FEATURE, //\r\n                fastJsonConfig.getSerializerFeatures());\r\n        headers.setContentLength(len);\r\n        OutputStream out = outputMessage.getBody();\r\n        outnew.writeTo(out);\r\n        outnew.close();\r\n    }\r\n\r\n请问在不修改 JSON.DEFFAULT_DATE_FORMAT的情况下，可以通过FastJsonConfig或注解设置反序列化时的日期格式吗？"}}
{"actor":{"display_login":"lifeixiang027"}}