Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误

org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '2012-12-12 12:01:01': not a valid representation (error: Can not parse date "2012-12-12 12:01:01": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
  at [Source: org.glassfish.jersey.message.internal.EntityInputStream@2c384e19; line: 1, column: 2] (through reference chain: jerseyspring.representation.Order["payTime"])
     at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
     at org.codehaus.jackson.map.deser.StdDeserializationContext.weirdStringException(StdDeserializationContext.java:243)
     at org.codehaus.jackson.map.deser.std.StdDeserializer._parseDate(StdDeserializer.java:577)
     at org.codehaus.jackson.map.deser.std.DateDeserializer.deserialize(DateDeserializer.java:28)
     at org.codehaus.jackson.map.deser.std.DateDeserializer.deserialize(DateDeserializer.java:19)
     at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
     at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)
     at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)
     at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
     at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
     at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
     at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)

解决方案:

import java.io.IOException;

import java.text.*;

import java.util.Date;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.*;

import com.fasterxml.jackson.databind.*;

public class CustomJsonDateDeserializer extends JsonDeserializer<Date> {

@Override
     public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 String date = jp.getText();
                 try {
                     return format.parse(date);
                 } catch (ParseException e) {
                     throw new RuntimeException(e);
                 }
     }

}

且在字段的setter上加上注解

@JsonDeserialize(using = CustomJsonDateDeserializer.class)

org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '2012-12-12 12:01:01': not a valid representation (error: Can not parse date "2012-12-的更多相关文章

  1. org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '20Spring Jackson 反序列化Date时遇到的问题

    Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误 org.codehaus.jackson.map.JsonMappingException: Can not cons ...

  2. SpringMVC 集成 jackson,日志格式报错:org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value

    org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from Str ...

  3. org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.

    2011-08-16 13:26:58,484 [http-8080-1] ERROR [core.web.ExceptionInterceptor] - org.codehaus.jackson.m ...

  4. hadoop出现ava.lang.ClassNotFoundException: org.codehaus.jackson.map.JsonMappingException

    Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jackson/map/JsonMa ...

  5. 报错:org.apache.sqoop.common.SqoopException Message: CLIENT_0001:Server has returned exception NoClassDefFoundError: org/codehaus/jackson/map/JsonMappingException

    报错背景: CDH集成sqoop2服务之后,创建好link和job之后,执行job的时候报错. 报错现象: sqoop:> start job -j Exception has occurred ...

  6. 报错:java.lang.ClassNotFoundException: org.codehaus.jackson.map.JsonMappingException

    报错背景: 执行hdfs-mysql的job任务的时候报错. 报错现象: Exception has occurred during processing command Exception: org ...

  7. Jackson错误:Can not deserialize instance of java.lang.String out of START_OBJECT token

    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not des ...

  8. JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of j

    异常信息如下: JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token ...

  9. at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142) :json转化“$ref 循环引用”的问题

    原因: entity实体中存在@OneToMany,@ManyToOne注解,在转化json是产生了循环引用 报的错误 解决方法: springmvc @ResponseBody 默认的json转化用 ...

随机推荐

  1. error 1044 (42000):access denied for user ''@'localhost' to database 'quickapp' 解决方法

    在虚拟机上重新创建一个数据库时,一直出现这个报错:error 1044 (42000):access denied for user ''@'localhost' to database 'quick ...

  2. springmvc防止重复提交拦截器

    一.拦截器实现,ResubmitInterceptorHandler.java import org.apache.commons.lang3.StringUtils; import org.spri ...

  3. Pwn入坑指南

    栈溢出原理 参考我之前发的一篇 Windows栈溢出原理 还有 brant 师傅的<0day安全笔记> Pwn常用工具 gdb:Linux下程序调试 PEDA:针对gdb的python漏洞 ...

  4. SpringMVC(十) RequestMapping RequestHeader注解

    在控制器方法中,通过类似 RequestHeader(value="Accept-Lanaguage") String lan 可以获取请求头信息. 控制器方法: package ...

  5. Ubuntu 安装Chrome

    apt方式安装Chrome 1.添加密匙 wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key a ...

  6. BZOJ.1923.[SDOI2010]外星千足虫(高斯消元 异或方程组 bitset)

    题目链接 m个方程,n个未知量,求解异或方程组. 复杂度比较高,需要借助bitset压位. 感觉自己以前写的(异或)高斯消元是假的..而且黄学长的写法都不需要回代. //1100kb 324ms #i ...

  7. SHOI2019旅游记

    题外话 为什么不更ZJOI day1的游记呢.... 因为考挂自闭了不想更.等day2考完再说咕咕咕 还是更个SHOI旅游记吧!反正不是自家省选,玩得真开心~~~ day0 SH好热好热啊,感觉到夏天 ...

  8. hdu 1754 I Hate It(树状数组区间求最值)2007省赛集训队练习赛(6)_linle专场

    题意: 输入一行数字,查询第i个数到第j个数之间的最大值.可以修改其中的某个数的值. 输入: 包含多组输入数据. 每组输入首行两个整数n,m.表示共有n个数,m次操作. 接下来一行包含n个整数. 接下 ...

  9. hashCode()方法与equals()方法

    摘自别人的评论:http://blog.csdn.net/fhm727/article/details/5221792 当向集合Set中增加对象时,首先集合计算要增加对象的hashCode码,根据该值 ...

  10. Tesseract OCR简单实用介绍

    做字符识别,不能不了解google的Tesseract-OCR,但是如何在自己的工程中使用其API倒是语焉不详,官网上倒是很详尽地也很啰嗦地介绍如何重新编译生成适合自己平台的lib和dll,经过近些天 ...