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

Allow Instant to be serialized as epochSecond without the fraction part

Đang mở
#116 20 bình luận 4 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
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với InstantSerializerBase.serialize(T value, JsonGenerator generator, SerializerProvider provider) và cách xử lý timestamp và nano giây được trình bày. Truy vết cách @JsonFormat(shape = JsonFormat.Shape.NUMBER) và các tính năng của mapper chọn đường dẫn này, sau đó xác định cấu hình tiêu chuẩn được dự kiến để bỏ qua phần phân số. Hoàn tất khi timestamp epoch của Instant được serialize thành một số nguyên biểu thị số giây kể từ epoch mà không cần getter tùy chỉnh.

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

Mô tả

date-time-config new-feature

I have an Instant field that represents an epoch timestamp in seconds.

    @JsonProperty("registered_at")
    @JsonFormat(shape = JsonFormat.Shape.NUMBER)
    private Instant registeredAt;

the mapper is configured this way

    .featuresToDisable(ADJUST_DATES_TO_CONTEXT_TIME_ZONE,
                       FAIL_ON_UNKNOWN_PROPERTIES,
                       WRITE_DATES_AS_TIMESTAMPS,
                       SORT_PROPERTIES_ALPHABETICALLY)

However when this gets serialized as

"registered_at" : 1420324047.000000000

By looking at the code there's no way to serialize this value as epoch seconds using the standard mechanism.

InstantSerializerBase.serialize(T value, JsonGenerator generator, SerializerProvider provider)

        if (useTimestamp(provider)) {
            if (useNanoseconds(provider)) {
                generator.writeNumber(DecimalUtils.toBigDecimal(
                        getEpochSeconds.applyAsLong(value), getNanoseconds.applyAsInt(value)
                ));
                return;
            }
            generator.writeNumber(getEpochMillis.applyAsLong(value));
            return;
        }

The only option is to use :

    @JsonGetter("registered_at")
    public long getRegisteredAtEpoch() {
        return registeredAt.getEpochSecond();
    }

It could be nice if there could be way to tell jackson to avoid serializing the fraction part.

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.