首页 > 其他分享 >while it seems to fit format ‘yyyy-MM-dd‘T‘HH:mm:ss.SSSZ‘, parsing fails (leniency? null))

while it seems to fit format ‘yyyy-MM-dd‘T‘HH:mm:ss.SSSZ‘, parsing fails (leniency? null))

时间:2022-12-21 11:32:52浏览次数:42  
标签:fails java 07 ss springframework yyyy HH org null


我们知道前端提交字符串到后台映射为Date类型可以加上​​@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")​​注解,但是这次加了还是报错

前端提交字符串到后台,出现如下错误:

​while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))​

while it seems to fit format ‘yyyy-MM-dd‘T‘HH:mm:ss.SSSZ‘, parsing fails (leniency? null))_json


错误的大致意思就是字符串映射到Date类型失败,说我们的格式的确是符合的,但是还是映射失败

完整错误:

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2020-07-31 07:25:29": not a valid representation (error: Failed to parse Date value '2020-07-31 07:25:29': Cannot parse date "2020-07-31 07:25:29": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-07-31 07:25:29": not a valid representation (error: Failed to parse Date value '2020-07-31 07:25:29': Cannot parse date "2020-07-31 07:25:29": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
at [Source: (PushbackInputStream); line: 1, column: 87] (through reference chain: com.xb.entity.Meeting["endTime"])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:241)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:223)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:206)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at
..........

我们知道前端提交字符串到后台映射日期类型的话,加上​​@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")​​注解就行了,本人亲测SpringMVC环境可行,但此次报错的项目是SpringBoot项目,不知道是SpringBoot项目导致的转换失败还是SpringBoot项目所使用的SpringMVC版本太高才导致转换失败(这个有兴趣的小伙伴可以测试)

  • 解决方案:

在​​application.yml​​中添加如下配置

spring: 
jackson:
date-format: yyyy-MM-dd HH:mm:ss


标签:fails,java,07,ss,springframework,yyyy,HH,org,null
From: https://blog.51cto.com/u_15919174/5959197

相关文章

  • java.lang.ClassNotFoundException
    当你用Eclipse或者MyEclipse运行javaweb项目时,发现连接数据库失败,出现提示java.lang.ClassNotFoundException,你确定你的jar包添加了,那么很有可能是你项目的本地lib没有......
  • [css] before和:after实现div下方的小三角
    <divclass="pop-box">aaa</div>.pop-box{position:absolute;width:250px;height:260px;background-color:#fff;border:1pxsolid#ccc;bord......
  • [vue] Vue绑定class样式
    1.class样式写法:class=“xxx”xxx可以是字符串、对象、数组。字符串写法适用于:类名不确定,要动态获取。对象写法适用于:要绑定多个样式,个数不确定,名字也不确定。数组写法适......
  • [css3] 多列布局案例
    使用多列划分属性:column-count:5;<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><......
  • [css] 半圆
    制作上半圆,实现原理:把高度height设置为宽度width的一半,并且左上角和右上角的圆角半径定义为元素的高度一致,而右下角和左下角的圆角半径定义为0.<!DOCTYPEhtml><htmllang="......
  • [css] 画直线
    width:42px;height:0;border-bottom:3pxsolid#006da9;......
  • [css3] 多背景属性background
    background:url(img_flwr.gif)rightbottomno-repeat,url(paper.gif)lefttoprepeat;<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaht......
  • [CSS3] 绘制六边形
    #hexagon{width:100px;height:55px;background:red;position:relative;}#hexagon:before{content:"";position:absolute;......
  • [css] 毛玻璃 backdrop-filter: blur
    backdrop-filter:blur(10px)​​CSS毛玻璃效果的实现与应用​​......
  • [css] 小案例---用position:定位小窗口位于版面正中心
    fixed常用<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"cont......