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 ...
随机推荐
- Linux命令——sync
参考:A Step-By-Step Guide to Using the Linux sync Command 前言 数据只有被读入内存才能被CPU所处理,但是数据又常常需要由内存写回磁盘当中(例如储 ...
- 利用ssh的用户配置文件config管理ssh会话
通常利用 ssh 连接远程服务器,一般都要输入以下类似命令: ssh user@hostname -p port 如果拥有多个 ssh 账号,特别是像我这种喜欢在终端里直接 ssh 登陆,不用 PuT ...
- Navicat连接MySQL数据库出现 ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded
装了mysql 8之后因为mysql8采用了新的加密方式,很多软件还不支持, 解决方法如下: 1. 管理员权限运行命令提示符,登陆MySQL mysql -u root -p 2. 修改账户密码加密规 ...
- 【转】An introduction to using and visualizing channels in Go
An introduction to using and visualizing channels in Go 原文:https://www.sohamkamani.com/blog/2017/08/ ...
- *JavaScript标准参考教程 - 阮一峰
参考 页向对象编程的模式(继承&模块化)
- Fiddler——如何抓取PHP的curl请求
前言 本文主要介绍如何使用fiddler工具,来进行抓取PHP的curl请求,如果你会使用fiddler,那就是一行代码的事, 不会也没事,本文会教你如何简单的使用. 步骤 代码 设置桥接网络为127 ...
- 二.protobuf3数据类型
定义数据类型 首先让我们看一个非常简单的例子.假设您想要定义搜索请求消息格式,其中每个搜索请求都有一个查询字符串.您感兴趣的特定结果页面以及每页的结果数量.这是用来定义消息类型的.proto文件. s ...
- native与H5优缺点及H5测试
一.native(原生)与H5优缺点介绍 native(原生)优点 1.运行速度快 2.可以应用到底层的API 3.便捷性与易用性 4.打开会比较节省流量 native(原生)缺点 1.不同操作系统需 ...
- java spring boot 导出/下载文本文件操作(包含写文本文件)
内容简介 本文主要内容为使用java把内容写入文本文件,并实现下载/导出的功能. 实现步骤 1. controller层 @ResponseBody @RequestMapping(value = & ...
- MySQL 索引原理以及慢查询优化
本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BTree ...