FasterXML / FasterXML/jackson-modules-java8

Absent nested optional shennanigans

Đang mở
#310 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
425
Fork
124
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Uh... so this is partially for science, I guess. It's obscure enough to not matter, but I'd like to understand the reasoning. I stumbled upon this because I am working on a smaller databind library myself and of course I'm always comparing to Jackson for sensible defaults. Observe the following:

```java
record R(Optional> s) { }

R r = new ObjectMapper()
.registerModule(new Jdk8Module())
.readValue("{}", new TypeReference<>() {});

assertFalse(r.s.isPresent());
```

Here, an `Optional>` property is absent from the JSON to deserialize. Naively, I expected the property to be set to an empty optional, but actually it's `Optional.of(Optional.empty())`, so the snippet above crashes.

I didn't find any tests which explicitly cover this here, so I guess it wasn't really considered a worthwhile edge case. But I think following through with these weird cases helps in figuring out consistent behaviour in general. Do you think that the current behaviour (`Optional.of(Optional.empty())`) is correct or do you think `Optional.empty()` would be correct?

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

Đánh giá

Issue này chưa được đánh giá.

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.