`Optional<JsonNode>` deserialization from "absent" value does not work in the expected way
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 50/100
Hướng nghiên cứu
Bắt đầu trong jackson-datatype-jdk8 OptionalDeserializer và theo dõi cách xử lý thuộc tính bị thiếu qua PropertyValueBuffer::_findMissing, JsonDeserializer#getAbsentValue và JsonNodeDeserializer#getNullValue. Xác nhận hành vi của ví dụ MyRecord được deserializes từ {} và đảm bảo Optional bị thiếu vẫn rỗng thay vì bọc một NullNode; kiểm tra kết quả mong đợi bằng các bài kiểm thử hiện có của dự án.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Example:
public record MyRecord(
Optional<JsonNode> myField
) {
}
When deserialized from: {}
Expected:
myField.isPresent() == false
Actual:
myField.isPresent() == true
This is because myField gets set to an Optional of a NullNode
After spending some time looking into the source code of both the jackson-databind and the jackson-datatype-jdk8 libraries, the problem seems to lie in the OptionalDeserializer (or higher).
During deserialization, when a property is missing, the PropertyValueBuffer::_findMissing method is called and in it, this piece of code is called:
https://github.com/FasterXML/jackson-databind/blob/0fe97e0d69b7d5362907b094d5b979bc2216dc4a/src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyValueBuffer.java#L203
// Third: NullValueProvider? (22-Sep-2019, [databind#2458])
// 08-Aug-2021, tatu: consider [databind#3214]; not null but "absent" value...
Object absentValue = prop.getNullValueProvider().getAbsentValue(_context);
if (absentValue != null) {
return absentValue;
}
The OptionalDeserializer is not overriding its inherited getAbsentValue method to return Optional.ofNullable(_valueDeserializer.getAbsentValue(ctxt)); (or similar).
Due to the lack of the overriding, the inherited getAbsentValue method actually calls getNullValue instead as can be seen here:
https://github.com/FasterXML/jackson-databind/blob/0fe97e0d69b7d5362907b094d5b979bc2216dc4a/src/main/java/com/fasterxml/jackson/databind/JsonDeserializer.java#L349
@Override
public Object getAbsentValue(DeserializationContext ctxt) throws JsonMappingException {
return getNullValue(ctxt);
}
In the case of a JsonNode, the JsonNodeDeserializer is used. This deserializer overrides the getNullValue method to return a NullNode.
@Override
public JsonNode getNullValue(DeserializationContext ctxt) {
return ctxt.getNodeFactory().nullNode();
}
- 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ự
-
certification
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
[BUG] ECR GetAuthorizationToken returns a proxyEndpoint for the default region, not the request's Đang mởbug ecr
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Needs: Triage Type: Feature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
AntennaPod/AntennaPod#8794 ·
-
agentic-workflows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
github/copilot-sdk#2760 ·