使用 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 注释您的 Field 以解决您的错误,您必须确保它具有所有时间单位。
下面是一个例子:
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/