gpt4 book ai didi

rest - Payara 5 中的日期格式已更改(Long 不再有效)-- org.eclipse.yasson.YassonProperties#ZERO_TIME_PARSE_DEFAULTING

转载 作者:行者123 更新时间:2023-12-02 04:30:45 25 4
gpt4 key购买 nike

使用 Payara 4.174 并在后端接收很长的日期,例如 1540545780000。现在,我升级到 Payara 版本 5。

public User {
String name;
Date birthdate;
}

@POST
@Path("/user/)
public void createUser(User user) {
...
}

json call
{
name: "name",
birthdate: 1540545780000
}

现在调用因以下错误而中断:

Caused by: javax.json.bind.JsonbException: Error parsing class java.util.Date from value: 1540545780000. Check your @JsonbDateFormat has all time units for class java.util.Date type, or consider using org.eclipse.yasson.YassonProperties#ZERO_TIME_PARSE_DEFAULTING.
at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.deserialize(AbstractDateTimeDeserializer.java:70)
at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserializeInternal(AbstractContainerDeserializer.java:85)
at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserialize(AbstractContainerDeserializer.java:61)
at org.eclipse.yasson.internal.Unmarshaller.deserializeItem(Unmarshaller.java:62)
at org.eclipse.yasson.internal.Unmarshaller.deserialize(Unmarshaller.java:52)
at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:45)
at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:85)
at org.glassfish.jersey.jsonb.internal.JsonBindingProvider.readFrom(JsonBindingProvider.java:99)
... 62 common frames omitted
Caused by: java.time.format.DateTimeParseException: Text '1540545780000' could not be parsed at index 0

最佳答案

乔纳森说对了一部分。您不必编写自定义 DateTypeDeserializer 来解决您的问题。但是,正如错误消息所描述的,您可以使用@JsonbDateFormat注释您的字段来解决您的错误,您必须确保它具有所有时间单位。

这是一个例子:

public User {
String name;
@JsonbDateFormat(value = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
Date birthdate;
}

关于rest - Payara 5 中的日期格式已更改(Long 不再有效)-- org.eclipse.yasson.YassonProperties#ZERO_TIME_PARSE_DEFAULTING,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53118216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com