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 String value '2012-12-12 12:01:01': not a valid representation (error: Can not parse date "2012-12- - 故宫博物院 - 博客园
https://www.cnblogs.com/suizhikuo/p/8393781.html
关于jackson中时间字符串的转换 - masquelo的专栏 - CSDN博客
https://blog.csdn.net/masquejava/article/details/10556281
org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from Str - kero921的博客 - CSDN博客
https://blog.csdn.net/kero921/article/details/79835627
package org.jeecgframework.core.common.controller; import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;
import org.springframework.util.StringUtils;
/**
* 解决@RequestBody接收json数据,Jackson 反序列化Date格式
* @author scott
*
*/
public class CustomJsonDateDeserializer extends JsonDeserializer<Date> {
private SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String text = jp.getText(); if (StringUtils.hasText(text)) {
try {
if (text.indexOf(":") == -1 && text.length() == 10) {
return this.dateFormat.parse(text);
} else if (text.indexOf(":") > 0 && text.length() == 19) {
return this.datetimeFormat.parse(text);
} else {
throw new IllegalArgumentException("Could not parse date, date format is error ");
}
} catch (ParseException ex) {
IllegalArgumentException iae = new IllegalArgumentException("Could not parse date: " + ex.getMessage());
iae.initCause(ex);
throw iae;
}
} else {
return null;
}
} }
//商品有效期限
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private java.util.Date goodsdates; @Column(name ="goodsdates",nullable=true,length=20)
@JsonDeserialize(using = CustomJsonDateDeserializer.class)
public java.util.Date getGoodsdates() {
return goodsdates;
} public void setGoodsdates(java.util.Date goodsdates) {
this.goodsdates = goodsdates;
}
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 String value '20Spring Jackson 反序列化Date时遇到的问题
Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误 org.codehaus.jackson.map.JsonMappingException: Can not cons ...
- 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-
Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误 org.codehaus.jackson.map.JsonMappingException: Can not cons ...
- 【开发遇到的问题】Spring Mvc使用Jackson进行json转对象时,遇到的字符串转日期的异常处理(JSON parse error: Can not deserialize value of type java.util.Date from String[)
1.问题排查 - 项目配置 springboot 2.1 maven配置jackson - 出现的场景: 服务端通过springmvc写了一个对外的接口,查询数据中的表,表中有一个字段属性是时间戳,返 ...
- SSM报错:No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverter
我使用的是SSM框架,是在编写测试RESTFUL接口的时候出现, @RequestMapping(value = "/selectAll", method = RequestMet ...
- 【报错】No converter found for return value of type: class java.util.HashMap
ssm开发碰到的错误 @ResponseBody的作用是是将java对象转为json格式的数据 @ResponseBody注解标识该方法的返回值直接写回到HTTP响应体中去(而不会被被放置到Model ...
- 解决:oracle+myBatis ResultMap 类型为 map 时返回结果中存在 timestamp 时使用 jackson 转 json 报错
前言:最近在做一个通用查询单表的组件,所以 sql 的写法就是 select *,然后 resultType="map" ,然后使用 jackson @ResponseBody 返 ...
- 开启bin-log日志mysql报错:This function has none of DETERMINISTIC, NO SQL解决办法
开启bin-log日志mysql报错:This function has none of DETERMINISTIC, NO SQL解决办法: 创建存储过程时 出错信息: ERROR 1418 (HY ...
- SpringBoot与jackson.databind兼容报错问题
SpringBoot与jackson.databind兼容报错问题 ———————————————— 1.SpringBoot版本V2.0.0其依赖的jackson-databind版本为V2.9.4 ...
- 报错:Missing type map configuration or unsupported mapping
报错:Missing type map configuration or unsupported mapping □ 背景 当把View Model转换成Domain Model保存的时候,发生在Au ...
随机推荐
- VBS 自动发消息给对方
http://www.vbsedit.com/ Dim Name,Msg Name= "我家丫头" Msg = "333" set ws=wscript.cre ...
- Codes: MODERN ROBOTICS Ch.4_基于PoE的正运动学代码实现
%%1 基于PoE space form 的正运动学求解 % 输入M矩阵.螺旋轴列表Slist(column vector).关节角向量qlist(column vector),输出齐次变换矩阵T f ...
- 用python爬取全网妹子图片【附源码笔记】
这是晚上没事无聊写的python爬虫小程序,专门爬取妹子图的,养眼用的,嘻嘻!身为程序狗只会这个了! 废话不多说,代码附上,仅供参考学习! """ 功能:爬取妹子图全网妹 ...
- Bias vs. Variance(2)--regularization and bias/variance,如何选择合适的regularization parameter λ(model selection)
Linear regression with regularization 当我们的λ很大时,hθ(x)≍θ0,是一条直线,会出现underfit:当我们的λ很小时(=0时),即相当于没有做regul ...
- matlab运行程序时出现failed to start a parallel pool
运行matlab做并行时得到如下报错: failed to start a parallel pool. (For information in addition to the causing err ...
- Linux 文件系统缓存 -针对不同数据库有不同作用
文件系统缓存 filesystem cache 许多人没有意识到.文件系统缓存对于性能的影响.Linux系统默认的设置倾向于把内存尽可能的用于文件cache,所以在一台大内存机器上,往往我们可能发现没 ...
- MongoDB bindIp 与 bindIpAll
Linux服务器上安装MongoDB后,允许其它客户端IP访问MongoDB服务器.阿里云服务器需要设置入站规则,可参见使用外网访问阿里云服务器ZooKeeper 1.允许所有地址访问 NOTE:ne ...
- 表述数据的手段——json
一.JSON 语法规则 在 JS 语言中,一切都是对象.因此,任何支持的类型都可以通过 JSON 来表示,例如字符串.数字.对象.数组等.但是对象和数组是比较特殊且常用的两种类型: 对象表示为键值对 ...
- mount命令设备的挂载和卸载
不能挂载到根目录:其他目录都可以 1.光盘设备挂载到mnt mount -t iso99660 /dev/cdrom /mnt 2.光盘镜像文件.so文件挂载到mnt mount -o loop -t ...
- JPA 原生SQ查询
参考文章 https://blog.csdn.net/coding_1994/article/details/84575943 https://blog.csdn.net/m0_37776094/ar ...