[Java][JSON] No way to reject a repeated JSON property on read
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Read the existing failOnMissingRequiredProperties builder option and compare how JSON readers are generated and interpreted; the issue names both paths but gives no file locations or tests. Then assess how class annotations, mixins, flattened properties, null handling, and nested classes fit the proposed duplicate detection semantics. Done means a per-class option rejects repeated known properties while preserving the stated behavior for unknown, ignored, and any-setter entries.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens
When a JSON object repeats one of the bean's known properties, fory-json keeps the last value without an error.
There is no builder option and no annotation that rejects such a document.
public static class Request {
public String id;
public Long tmax;
public List<String> bcat = List.of();
}
ForyJson fory = ForyJson.builder().build();
Request r = fory.fromJson(
"{\"id\":\"r1\",\"tmax\":100,\"bcat\":[\"IAB1\"],\"tmax\":200,\"bcat\":[]}", Request.class);
// tmax=200 bcat=[]
Reproduced on main (b6023929) and on 1.7.6, JDK 25.
Why it matters
RFC 8259 leaves duplicate names to the implementation, and parsers disagree on them: some take the first value,
some the last, some fail. A service that receives a document from a third party and passes it on (or checks it
in one component and acts on it in another) can therefore read a different value than the next hop does. For
input validation it is useful to refuse such a document outright.
Our case: we receive OpenRTB bid requests from external exchanges and answer a request that repeats a top-level
field ("tmax", "imp", ...) with HTTP 400. Nested objects of the same request stay lenient, and so do our
other models. Today we do this on Jackson with a custom module that wraps the root properties of one class. With
Fory there is no hook for it, so this is one of the things that keep us from moving the inbound request read to
Fory.
Jackson only offers StreamReadFeature.STRICT_DUPLICATE_DETECTION, which is parser-wide: it applies to every
object and map in every document and keeps a name set per object, so it costs every read. A per-class switch is
both cheaper and closer to what applications need.
Proposal
ForyJsonBuilder.failOnDuplicateProperties(boolean), defaultfalse(today's behaviour: the last value
wins), next tofailOnMissingRequiredProperties.- A class annotation
@JsonDuplicateProperties(fail = true | false)that overrides the builder setting for one
class. Like@JsonInclude, it is not inherited, and an exact-target@JsonMixincan supply it.
Semantics when enabled for a class:
- A known property of that class (field, setter,
@JsonCreatorparameter, a name flattened in by
@JsonUnwrapped) that appears twice in one object fails the read with aForyJsonExceptionthat names the
property. - An explicit
nullcounts as an occurrence, also whenonNullReadisSKIP. - Unknown and ignored names, and
@JsonAnySetterentries, are not tracked. - Nested objects follow their own class setting; enabling it on the root does not make children strict.
Cost: when disabled, the generated readers stay exactly as they are today (the decision is made at code
generation time, like onNullRead). When enabled, each object of that class marks one bit per known property
it reads, so there is no per-read allocation and no name set.
I have an implementation in progress for the generated readers and the interpreter and would like to open a PR
for it if this direction is acceptable. Happy to adjust the API shape (for example an enum instead of the
boolean, or only the class annotation) to whatever fits the project better.
- Ngôn ngữ chính
- Java
- Star
- 4.6k
- Fork
- 470
- Merge trung bình
- 9 giờ 28 phút
- Pull request đã merge (30 ngày)
- 33
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
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 apache/fory
-
[Python] Compatible xlang read silently drops fields when the peer writes camelCase/PascalCase namesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Build] Add ASF license headers to config files that allow commentsCó thể làm lại được @Swatantra-66 đã nhận 27 ngày trước và không có pull request nào đang mở. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/fory#4124 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
xlang: the snake_case conversion of field names is not specified, and the runtimes do not agreeCó thể làm lại được @dhruv-dagar đã nhận 14 ngày trước và không có pull request nào đang mở. Đang mởbug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
apache/fory#4187 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Rust] Add an option to use Rust native enumCó thể đã có người làm @BaldDemian đã nhận 18 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/fory#4177 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Untyped read collapses a number literal that does not fit a doubleCó thể đã có người làm @mohitjoshi-hey đã nhận 20 ngày trước. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
apache/fory#4170 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
liberation-data/drivine4j#547 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
BindingServiceProperties.bindings regressed to a non-thread-safe TreeMap in GH-3158: concurrent first use of binding names corrupts itCó thể đã có người làm @AkashB23 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
spring-cloud/spring-cloud-stream#3321 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] 资源包列表 与 模组/数据包/世界 列表排列顺序不一致Có thể đã có người làm @fishdry1000 đã nhận 4 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-driven-fuzzing bug claude Minor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linagora/twake-calendar-side-service#1333 ·
Maintainer thường phản hồi trong vòng 1 ngày