Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

OffsetTimeSerializer not writing seconds for time object like 15:30:00Z (where seconds is 00)

Đang mở
#299 4 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu với datetime/src/main/java/tools/jackson/datatype/jsr310/ser/OffsetTimeSerializer.java, đặc biệt là _serializeAsArrayContents, và tái hiện việc tuần tự hóa 15:00:00Z bằng JavaTimeModule. Xác nhận biểu diễn thời gian JSON được mong đợi và xác định xem hành vi được yêu cầu hay một serializer hook có thể ghi đè là phù hợp; công việc được xem là hoàn tất khi hành vi này được bao phủ bởi một regression test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

pr-welcome test-needed

When having a OffsetTime field with e.g. 15:00:00Z and serializing this with Jackson it outputs:
15:00Z and thus the seconds are lost.

Note I have the time module registered via JavaTimeModule().

Although one could argue that the seconds are not needed this gives some problems when validating outputted data against JSON schema.
when using the JSON schema format time then the seconds are expected, see https://json-schema.org/understanding-json-schema/reference/string#dates-and-times
without the seconds the JSON schema validator fails with: The value must be a valid time.
(note I'm using Justify for schema validation)

Looking at the source code, I see this is done on purpose
https://github.com/FasterXML/jackson-modules-java8/blob/master/datetime/src/main/java/tools/jackson/datatype/jsr310/ser/OffsetTimeSerializer.java#L92-L111

    private final void _serializeAsArrayContents(OffsetTime value, JsonGenerator g,
            SerializerProvider provider)
        throws JacksonException
    {
        g.writeNumber(value.getHour());
        g.writeNumber(value.getMinute());
        final int secs = value.getSecond();
        final int nanos = value.getNano();
        if ((secs > 0) || (nanos > 0)) {
            g.writeNumber(secs);
            if (nanos > 0) {
                if(useNanoseconds(provider)) {
                    g.writeNumber(nanos);
                } else {
                    g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
                }
            }
        }
        g.writeString(value.getOffset().toString());
    }

Is it possible to override this behaviour?

Currently I think my only option is create a custom Serializer?

If not possible to override this behaviour would it be at least possible to change this _serializeAsArrayContents method from private to protected so one could simply extend this class and override this method?

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của FasterXML/jackson-modules-java8

Tất cả issue của FasterXML/jackson-modules-java8

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.