Java 8 date/time type `java.time.LocalDate` not supported

java8 LocalDate/LocalDateTime的序列化和反序列化报错的解决方法:

程序报错:"Could not write JSON: Java 8 date/time type `java.time.LocalDate` not supported by default: add Module \"com.fasterxml.jackson.datatype:jackson-datatype-jsr310\"的解决方式如下:

LocalDate类型:

/**
 * 签约日期
 */
@Schema(description = "签约日期,格式:YYYY-MM-DD")
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8", shape = JsonFormat.Shape.STRING)
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
private LocalDate signDate;

 LocalDateTime类型:

/**
     * 申请日期
     */
@Schema(description = "申请日期")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", shape = JsonFormat.Shape.STRING)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime applicantDate;

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Conversion not supported for type java.time.LocalDate错误通常是由于数据库驱动包版本不兼容导致的。根据引用\[1\]和引用\[2\]的内容,可以看出在使用Spring Boot和MyBatis-Plus时,需要确保mysql-connector-java版本不低于5.1.37,并且其他依赖版本也要符合要求。如果你的项目是一个大项目,不方便进行升级,那么可以尝试以下解决方法: 1. 检查你的项目中mysql-connector-java的版本是否低于5.1.37。如果是低于这个版本的话,可以尝试将其升级到5.1.37或更高版本。 2. 检查其他相关依赖的版本是否符合要求。根据引用\[1\]和引用\[2\]的内容,你需要确保spring-tx、mybatis-plus-boot-starter和druid-spring-boot-starter的版本都符合要求。 3. 如果你无法升级依赖版本,可以尝试使用其他方法解决这个问题。根据引用\[3\]的内容,可以参考链接中提供的解决方法进行尝试。 总结来说,Conversion not supported for type java.time.LocalDate错误通常是由于数据库驱动包版本不兼容导致的。你可以尝试升级mysql-connector-java版本和其他相关依赖的版本,或者参考其他解决方法来解决这个问题。 #### 引用[.reference_title] - *1* [Conversion not supported for type java.time.LocalDateTime报错](https://blog.csdn.net/qq976748881/article/details/118941044)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Conversion not supported for type java.time.LocalDateTime](https://blog.csdn.net/J_XiaoW/article/details/120413088)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [conversion to class java.time.LocalDateTime from 8 not supported处理解决](https://blog.csdn.net/qq_41766663/article/details/130719844)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值