[Java][JSON] No way to reject a repeated JSON property on read
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 4.6k
- Fork
- 470
- Merge medio
- 9h 28m
- PR unite (30g)
- 33
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/fory
-
[Python] Compatible xlang read silently drops fields when the peer writes camelCase/PascalCase namesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
[Build] Add ASF license headers to config files that allow commentsForse di nuovo libera @Swatantra-66 l’ha presa 27 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/fory#4124 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
xlang: the snake_case conversion of field names is not specified, and the runtimes do not agreeForse di nuovo libera @dhruv-dagar l’ha presa 14 giorni fa e non c’è nessuna pull request aperta. Apertabug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
apache/fory#4187 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Rust] Add an option to use Rust native enumForse già presa @BaldDemian l’ha presa 18 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
apache/fory#4177 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Untyped read collapses a number literal that does not fit a doubleForse già presa @mohitjoshi-hey l’ha presa 20 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
apache/fory#4170 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 3 giorni
-
A proxy that fails to start logs a RejectedExecutionException stack trace from its shutdown hookApertafollow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Sanne/incus-spawn#1953 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
Shweit/EtherealPortals#30 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
checkstyle/checkstyle#22398 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Typo in jakartaee-bom 12.0.0-SNAPSHOT with cdiForse già presa @ElectLive l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
jakartaee/jakartaee-api#205 · 1 commento ·