Validate embedded objects for ZoneId, Period and ZoneOffset
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
- 72/100
Hướng nghiên cứu
Start with JSR310StringParsableDeserializer and its VALUE_EMBEDDED_OBJECT branch, then reproduce the behavior using the CBOR generic Map<String, ZoneId> example and the corresponding List, Period, and ZoneOffset cases. Done means compatible embedded values still deserialize, while incompatible values are rejected with a normal Jackson mapping exception.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
As requested after reporting this by email, I am filing it here as a regular validation bug.
JSR310StringParsableDeserializer returns JsonParser.getEmbeddedObject() without checking that the returned object matches the requested type. With a binary data format and a type-erased generic container, this allows (for example) a CBOR byte string to be stored as the value of a Map<String, ZoneId> without any exception.
This affects the shared deserializer used for ZoneId, Period, and ZoneOffset.
Version information
jackson-datatype-jsr310: 2.22.2jackson-dataformat-cbor: 2.19.2- Java 8
The behavior was also reproduced against the current 2.x branch (2.23.0-SNAPSHOT).
Minimal reproduction
ObjectMapper mapper = new ObjectMapper(new CBORFactory());
mapper.registerModule(new JavaTimeModule());
ByteArrayOutputStream out = new ByteArrayOutputStream();
CBORGenerator gen = new CBORFactory().createGenerator(out);
gen.writeStartObject();
gen.writeFieldName("zone");
gen.writeBinary(new byte[] {
(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF
});
gen.writeEndObject();
gen.close();
Map<String, ZoneId> result = mapper.readValue(
out.toByteArray(),
new TypeReference<Map<String, ZoneId>>() { });
Object value = result.get("zone");
System.out.println(value.getClass());
System.out.println(value instanceof byte[]);
Output:
class [B
true
The same behavior occurs for a List<ZoneId> and for the Period and ZoneOffset deserializers.
Expected behavior
The embedded object should be accepted only if it is compatible with the requested target type. An incompatible value should produce a normal Jackson mapping exception, such as MismatchedInputException.
Actual behavior
The raw byte[] is returned and inserted into the generic container. No exception is raised during deserialization.
A directly typed POJO field does fail because reflective field assignment performs an independent runtime type check. Generic map values and collection elements do not have that check because of type erasure.
Cause
The VALUE_EMBEDDED_OBJECT branch returns the object directly:
} else if (p.hasToken(JsonToken.VALUE_EMBEDDED_OBJECT)) {
return p.getEmbeddedObject();
}
JSR310StringParsableDeserializer extends JSR310DeserializerBase<Object>, so no compiler-generated cast validates the returned value. The other JSR-310 deserializers that explicitly cast their embedded values fail immediately instead of silently placing the wrong type in the container.
One possible fix is to verify the embedded value against handledType() / _valueClass and route an incompatible value through DeserializationContext.handleUnexpectedToken(...).
- 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
-
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 ·
-
OffsetTimeSerializer not writing seconds for time object like 15:30:00Z (where seconds is 00) Đang mởpr-welcome test-needed
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FasterXML/jackson-modules-java8#299 · 4 bình luận · 1 reaction ·
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 ·