当前位置:网站首页>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;
边栏推荐
- High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
- Oracle condition, circular statement
- Relevant implementation records of CSI and local disk
- Scripting and programming languages
- @The reason why the Autowired annotation is empty
- 若依实现下拉框
- 不会还有人只会用forEach遍历数组吧?
- Object object to list collection
- Openharmony gnawing paper growth plan -- json-rpc
- YYGH-7-用户管理
猜你喜欢

YYGH-BUG-03

High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
![RL practice (0) - and the platform xinchou winter season [rule based policy]](/img/dc/10d615c64123475fea180e035095ff.png)
RL practice (0) - and the platform xinchou winter season [rule based policy]

Deep learning 19 loss functions

What are the advantages of e-mail marketing? Why do sellers of shopline independent station attach so much importance to it?

Lenovo hybrid cloud Lenovo xcloud, new enterprise IT service portal

How the third-party libraries in cocoapod reference local header files

JSP

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance

Common basic functions of Oracle
随机推荐
Example of MVVM framework based on kotlin+jetpack
CSI以及本地盘的相关实现记录
Jenkins持续集成1
socke.io長連接實現推送、版本控制、實時活躍用戶量統計
【无标题】
cocoapod中的第三方库怎么引用本地头文件
Shanghai Yuge ASR CAT1 4G module 2-way low power 4G application
What are the advantages of e-mail marketing? Why do sellers of shopline independent station attach so much importance to it?
lombok @EqualsAndHashCode 注解如何让对象.equals()方法只比较部分属性
PS effect understanding record 2 color_ dodge color_ burn
idea创建类时自动添加注释
Install redis on windows and permanently change the password, and integrate redis with the SSM framework
RL practice (0) - and the platform xinchou winter season [rule based policy]
Xcode13.3.1 项目执行pod install后报错
idea根据数据库表生成实体类
Small ball playing
The windows environment redis uses AOF persistence and cannot generate an AOF file. After generation, the content of the AOF file cannot be loaded
File foundation - read / write, storage
Differences between basic types and packaging classes
@Autowired注解为空的原因