jsonb 默认为 java api 的各种日期对象使用什么日期/时间格式?
例如,javascript 的 new Date().toJSON()
生成的输出包含我希望使用 Jsonb 解析到 ZonedDateTime
字段的第二个分数,但第二个分数是默认序列化器不支持。
我是否必须指定自定义格式来映射 javascript Date
?
最佳答案
Jsonb spec指定第 3.5 节中应支持的默认映射实现日期:
Implementations MUST support binding of the following standard Java date/time classes:
- java.util.Date
- java.util.Calendar
- java.util.GregorianCalendar
- java.util.TimeZone
- java.util.SimpleTimeZone
- java.time.Instant
- java.time.Duration
- java.time.Period
- java.time.LocalDate
- java.time.LocalTime
- java.time.LocalDateTime
- java.time.ZonedDateTime
- java.time.ZoneId
- java.time.ZoneOffset
- java.time.OffsetDateTime
- java.time.OffsetTime
一个javaindeed article列出了用于它们的各种格式化程序以及示例输出:
{
"date": "2016-07-27T23:07:41",
"calendar": "2016-07-27T23:07:41.782+02:00[Europe/Copenhagen]",
"gregorianCalendar": "2016-07-27T23:07:41.801+02:00[Europe/Copenhagen]",
"timeZone": "Europe/Copenhagen",
"simpleTimeZone": "Europe/Paris",
"instant": "2016-07-27T21:07:41.806Z",
"duration": "PT96H",
"period": "P3M",
"localDate": "2016-07-27",
"localTime": "23:07:41.807",
"localDateTime": "2016-07-27T23:07:41.807",
"zonedDateTime": "2016-07-27T23:07:41.807+02:00[Europe/Copenhagen]",
"zoneId": "Europe/Copenhagen",
"zoneOffset": "+03:30",
"offsetDateTime": "2016-07-27T23:07:41.807+02:00",
"offsetTime": "23:07:41.807+02:00",
}
就我而言,java.time.Instant
实例将从 javascript 的 Date.toJSON()
输出字符串中正确反序列化。
关于java - java日期对象默认的Jsonb序列化格式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60563836/