Feature request: DeserializationFeature.OPTIONAL_TIME_ZONE
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu với InstantDeserializer, thành phần xử lý các giá trị Instant và ZonedDateTime, rồi kiểm tra DeserializationContext#getTimeZone. Xác định DeserializationFeature.OPTIONAL_TIME_ZONE được đề xuất sẽ ảnh hưởng thế nào đến việc phân tích khi thiếu hậu tố, đồng thời giữ nguyên các múi giờ được chỉ định rõ ràng. Hoàn tất nghĩa là cả hai chuỗi ví dụ đều được giải tuần tự thành các giá trị tương đương với múi giờ dự phòng đã cấu hình, còn các đầu vào có múi giờ hiện có không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi,
In our project we need to accept ISO8601 date/time strings with optional time zones, where a specific time zone is to be assumed when the time zone is omitted from the string. In our specific case, the assumed time zone would be UTC, regardless of the system's current time zone.
So both of these strings would be deserialized to the same ZonedDateTime object:
- 2018-05-22T10:29:56Z
- 2018-05-22T10:29:56
Unfortunately, the latter cannot be deserialized to a ZonedDateTime (or an Instant for that matter), due to missing (and thus ambiguous) time zone information in the input string. Doing so would result in the following error:
java.lang.IllegalArgumentException: Cannot deserialize value of type `java.time.ZonedDateTime` from String "2018-05-22T10:29:56": Text '2018-05-22T10:29:56' could not be parsed at index 19
However, the specification that we are implementing in our project clearly states that the time zone of the string is supposed to be optional and if omitted, should be assumed to be UTC.
Currently, there is no way for us to tell Jackson to handle the input that way. And deserializing to LocalDateTime instead of ZonedDateTime would not be acceptable either, since that way, any explicitly specified time zone information would be ignored on deserialization.
What would really help here is a specific deserialization feature, named something like DeserializationFeature.OPTIONAL_TIME_ZONE. If enabled, the InstantDeserializer (used for deserializing to both Instant values and ZonedDateTime values) would then treat the time zone suffix (regardless of the notation, whether "Z", "+2:00" or whatever) as optional and assume the value of DeserializationContext#getTimeZone as the time zone when parsing temporal date/time input.
Perhaps there is an obvious existing way to solve this problem, but so far, I was unable to find it. If so, please let me know.
If not, could this proposed DeserializationFeature perhaps be implemented? Thank you kindly for considering this.
- Ngôn ngữ chính
- Java
- Star
- 425
- Fork
- 125
- Merge trung bình
- 19 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FasterXML/jackson-modules-java8
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
-
Wrap `DateTimeException` Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
FasterXML/jackson-modules-java8#382 · 3 bình luận ·
-
date-time-config
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FasterXML/jackson-modules-java8#374 · 31 bình luận · 1 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FasterXML/jackson-modules-java8#310 · 1 bình luận ·
-
Instants get not deserialized as expected sometimes (millis vs nanos, non-fractional numbers) Đang mởtest-needed
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
FasterXML/jackson-modules-java8#304 · 3 bình luận ·
Tất cả issue của FasterXML/jackson-modules-java8
Issue tương tự
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
apache/flink-agents#1152 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
jenkinsci/blueocean-plugin#5417 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
objectionary/eo-graphs#75 ·