当前位置:网站首页>Caused by: com. fasterxml. jackson. databind. Exc.invalidformatexception: exception resolution
Caused by: com. fasterxml. jackson. databind. Exc.invalidformatexception: exception resolution
2022-06-28 06:02:00 【zhou_ zhao_ xu】
Abnormal information :
Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2022-05-26 15:36:45": not a valid representation (error: Failed to parse Date value '2022-05-26 15:36:45': Cannot parse date "2022-05-26 15:36:45": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))
The reason for the error :
By default ,Jackson Use com.fasterxml.jackson.databind.util.StdDateFormat Class to format .
The time format is :yyyy-MM-dd’T’HH:mm:ss.SSSZ, by ISO-8601 data type .jackson The default date inverse sequence does not support yyyy-MM-dd HH:mm:ss This format , So deserialization failed
terms of settlement :
- Solution 1 : stay yml Configure the serialization format and time zone in the configuration
spring: jackson: date-format: yyyy-MM-dd HH:mm:ss # The default is StdDateFormat time-zone: GMT+8
- Solution 2 : Use... On the entity class date parameter jackson annotation
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date createTime;
- Solution three : Use... On the entity class date parameter fastjson annotation
<!-- fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.55</version> </dependency> <!-- jackson--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.11.3</version> </dependency>
@JSONField(format = “yyyy-MM-dd HH:mm:ss”) private Date createTime;
- Solution 4 : rewrite jackson Deserialization
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; 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); } } }
@JsonDeserialize(using = CustomJsonDateDeserializer.class) private Date createTime;
边栏推荐
- Independent station sellers are using the five e-mail marketing skills, do you know?
- Sharing tips for efficient scripting
- 自定义 cube-ui 弹出框dialog支持多个且多种类型的input框
- 简单手写debounce函数
- Simple handwritten debounce function
- ThreadLocal
- Xcode13.3.1 error reported after pod install
- Oracle fundamentals summary
- Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException:异常解决
- The length of pytorch dataloader the difference between epoch and iteration
猜你喜欢
Common basic functions of Oracle
深度學習19種損失函數
lombok @EqualsAndHashCode 注解如何让对象.equals()方法只比较部分属性
6. 毕业设计温湿度监控系统(ESP8266 + DHT11 +OLED 实时上传温湿度数据给公网服务器并在OLED显示屏上显示实时温湿度)
At first glance, I can see several methods used by motionlayout
Development trend of mobile advertising: Leveraging stock and fine marketing
Install and manage multiple versions of PHP under mac
Yygh-6-wechat login
How the third-party libraries in cocoapod reference local header files
函数栈帧的创建和销毁
随机推荐
Syn retransmission caused by IPVS
Filecoin黑客松开发者大赛
PKG package node project (express)
Example of MVVM framework based on kotlin+jetpack
The windows environment redis uses AOF persistence and cannot generate an AOF file. After generation, the content of the AOF file cannot be loaded
@Autowired注解为空的原因
socke.io长连接实现推送、版本控制、实时活跃用户量统计
How to add live chat in your Shopify store?
6. 毕业设计温湿度监控系统(ESP8266 + DHT11 +OLED 实时上传温湿度数据给公网服务器并在OLED显示屏上显示实时温湿度)
[MySQL] all query tables contain 20million data -- how to optimize SQL
阿里云短信服务(完整指南),短信发送功能实现。
Xcode13.3.1 项目执行pod install后报错
Install fmpefg
深度学习19种损失函数
Idea generates entity classes from database tables
Data middle office: an article that takes you to understand data middle office in simple terms
Deep learning 19 loss functions
High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
death_ satan/hyperf-validate
Oracle condition, circular statement