zoukankan      html  css  js  c++  java
  • 问题:Cannot deserialize value of type `java.util.Date` from String "2020-06-16"

    一、问题描述

    1.异常信息

    org.springframework.http.converter.HttpMessageNotReadableException: 
    JSON parse error:Cannot deserialize value of type `java.util.Date` from String "2020-06-16": not a valid representation (error: Failed to parse Date value '2020-06-16': Unparseable date: "2020-06-16"); 
    nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-06-16": not a valid representation (error: Failed to parse Date value '2020-06-16': Unparseable date: "2020-06-16")

    2.报错原因

    1)服务器用@RequestBody接收数据时,前端传的格式是yyyy-MM-dd;
    2)异常描述:反序列化失败,yyyy-MM-dd不是有效的格式。

    二、解决方案

    给对应实体属性添加@JsonFormat注释,pattern格式要与前端一致。

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd" , timezone = "GMT+8")
    private Date date;
  • 相关阅读:
    GitHub之初体验
    梦过去了
    转载:获取ISAPI_Rewrite重写后的URL
    看《分手合约》
    我们的家
    一盏灯的思考
    网站爱好者:开篇文
    致我们终将逝去的青春
    一起看看百度转码有多无耻!
    RPM
  • 原文地址:https://www.cnblogs.com/Jimc/p/13141171.html
Copyright © 2011-2022 走看看