美文网首页
mongodb的date类型通过feign传输出现解析异常

mongodb的date类型通过feign传输出现解析异常

作者: 机灵鬼鬼 | 来源:发表于2021-04-27 15:00 被阅读0次

    错误如下:

    "Error while extracting response for type [com.lppz.cic.common.model.ComResult<com.lppz.cic.common.model.dto.product.ProductDetailDto>] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String \"2021-08-25T16:03:25.884+00:00\": not a valid representation (error: Failed to parse Date value '2021-08-25T16:03:25.884+00:00': Unparseable date: \"2021-08-25T16:03:25.884+00:00\"); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String \"2021-08-25T16:03:25.884+00:00\": not a valid representation (error: Failed to parse Date value '2021-08-25T16:03:25.884+00:00': Unparseable date: \"2021-08-25T16:03:25.884+00:00\")\n at [Source: (PushbackInputStream); line: 1, column: 8611] (through reference chain: com.lppz.cic.common.model.ComResult[\"data\"]->com.lppz.cic.common.model.dto.product.ProductDetailDto[\"scene\"]->com.lppz.cic.common.model.dto.SceneDTO[\"expireAt\"])"
    

    解决方法,在业务model字段上添加注解,然后完美解决。

    /**
         * 创建时间
         */
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
        private Date createTime;
    

    相关文章

      网友评论

          本文标题:mongodb的date类型通过feign传输出现解析异常

          本文链接:https://www.haomeiwen.com/subject/bjaurltx.html