JSON请求Body Spring-boot REST API的OffsetDateTime避难所的问题

发布于 2025-01-24 16:10:53 字数 1132 浏览 4 评论 0原文

我在我的 pojo 中有一个oftsetDateTime字段:

@NotBlank(message = "startTime cannot be null or empty; ")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
@JsonSerialize(using = OffsetDateTimeSerializer.class)
private OffsetDateTime startTime;

当我尝试使用此OffsetTime JSON字段给API的请求主体时,显示避免误差: :解决

[org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Cannot deserialize value of type `java.time.OffsetDateTime` 
from String "2020-07-21T12:12:23.000+0200": 
Failed to deserialize java.time.OffsetDateTime: (java.time.format.DateTimeParseException) 
Text '2020-07-21T12:12:23.000+0200' could not be parsed at index 23;
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: 
Cannot deserialize value of type `java.time.OffsetDateTime` 
from String "2020-07-21T12:12:23.000+0200": 
Failed to deserialize java.time.OffsetDateTime: (java.time.format.DateTimeParseException) 
Text '2020-07-21T12:12:23.000+0200' could not be parsed at index 23

我的输入是正确的吗?

I'm having a OffsetDateTime field in my POJO:

@NotBlank(message = "startTime cannot be null or empty; ")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
@JsonSerialize(using = OffsetDateTimeSerializer.class)
private OffsetDateTime startTime;

When I try to give the request body for the API with this offsetTime JSON field, it shows deserialization error:
: Resolved

[org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Cannot deserialize value of type `java.time.OffsetDateTime` 
from String "2020-07-21T12:12:23.000+0200": 
Failed to deserialize java.time.OffsetDateTime: (java.time.format.DateTimeParseException) 
Text '2020-07-21T12:12:23.000+0200' could not be parsed at index 23;
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: 
Cannot deserialize value of type `java.time.OffsetDateTime` 
from String "2020-07-21T12:12:23.000+0200": 
Failed to deserialize java.time.OffsetDateTime: (java.time.format.DateTimeParseException) 
Text '2020-07-21T12:12:23.000+0200' could not be parsed at index 23

Is my input correct and how to deserialize this field from JSON?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文