[BUG] jackson3 JacksonJsonpMapper(ObjectMapper) fails to deserialize `_source` with "Trailing token" error
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- java, json
- Ambito
- developer-experience
Direzione di ricerca
Inizia in JacksonJsonpMapper.java a JacksonValueParser.deserialize, confrontando il workaround del costruttore senza argomenti con il percorso JacksonJsonpMapper(ObjectMapper). Riproduci con un mapper Jackson 3 fornito dall'utente e una lettura tipizzata di _source, quindi disabilita FAIL_ON_TRAILING_TOKENS solo per quella lettura parziale, come suggerisce l'issue. Aggiungi una copertura Jackson 3 dedicata in JacksonJsonpParserTest.java, che attualmente rispecchia il test Jackson 2. Fatto quando il caso del mapper fornito passa e il comportamento del mapper Jackson 3 viene testato separatamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What is the bug?
When a user-supplied Jackson 3 ObjectMapper is passed to org.opensearch.client.json.jackson3.JacksonJsonpMapper, deserializing any search response with a typed document fails:
tools.jackson.databind.exc.MismatchedInputException: Trailing token (`JsonToken.END_OBJECT`) found after value (bound as `Foo`): not allowed as per `DeserializationFeature.FAIL_ON_TRAILING_TOKENS`
at tools.jackson.databind.ObjectMapper._verifyNoTrailingTokens(ObjectMapper.java:2779)
at org.opensearch.client.json.jackson3.JacksonJsonpMapper$JacksonValueParser.deserialize(JacksonJsonpMapper.java:152)
In Jackson 3, FAIL_ON_TRAILING_TOKENS is enabled by default. JacksonValueParser calls objectMapper.readValue(jkParser, clazz) in the middle of the response stream (e.g. on _source), so the remaining tokens of the enclosing response trigger the check.
The no-arg constructor already works around this by disabling the feature, but the JacksonJsonpMapper(ObjectMapper) constructor uses the given mapper as is. This is a common path for Spring Boot 4 users, who pass the auto-configured JsonMapper (Jackson 3).
How can one reproduce the bug?
JsonpMapper mapper = new JacksonJsonpMapper(JsonMapper.builder().build())
.withAttribute("org.opensearch.client:Deserializer:_global.search.TDocument", JsonpDeserializer.of(Foo.class));
SearchResponse<Foo> r = fromJson(searchResponseJson, SearchResponse.class, mapper); // throws
With new JacksonJsonpMapper() the same code succeeds.
What is the expected behavior?
A user-supplied mapper should deserialize documents without having to know about this internal detail.
Possible fix
Disable the check only for this partial read, keeping the rest of the user's configuration:
return objectMapper.readerFor(clazz)
.without(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
.readValue(jkParser);
I verified this change locally: the user-supplied mapper case passes, and no other unit tests in java-client fail.
For reference, elasticsearch-java's Jackson3JsonpMapper applies the same configure() (which disables FAIL_ON_TRAILING_TOKENS) to user-supplied mappers as well, via rebuild() in the Jackson3JsonpMapper(JsonMapper) constructor (elastic/elasticsearch-java#1074). Aligning with that would also work.
Related
java-client/src/test/java/org/opensearch/client/opensearch/json/jackson3/JacksonJsonpParserTest.java is identical to the Jackson 2 test except for the package line, and imports org.opensearch.client.json.jackson.*. So the Jackson 3 mapper appears to have no dedicated test coverage, which is likely why this was not caught. I'd be happy to send a PR that fixes both.
What is your host/environment?
- opensearch-java 3.10.0 (also reproduced on main @ 839bd6b)
- Jackson 3 (Spring Boot 4.1.1), JDK 21
Do you have any screenshots?
N/A
Do you have any additional context?
Current workaround: jsonMapper.rebuild().disable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS).build() before passing it in.
- Lingua principale
- Java
- Stelle
- 165
- Fork
- 256
- Merge medio
- 1g 6h
- PR unite (30g)
- 37
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun 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 opensearch-project/opensearch-java
-
enhancement untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
opensearch-project/opensearch-java#2188 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] "shape" should not be required in GeoShapeQueryFieldForse di nuovo libera @lsh1215 l’ha presa 119 giorni fa e non c’è nessuna pull request aperta. Apertabug untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
opensearch-project/opensearch-java#2011 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
opensearch-project/opensearch-java#2008 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] ISM types lastUpdatedTime is susceptible to int overflowForse già presa @gingeekrishna l’ha presa 115 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
opensearch-project/opensearch-java#1898 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement untriaged
Difficoltà 4/5 3-5 giorni Idoneità per principianti 64/100
opensearch-project/opensearch-java#2195 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di opensearch-project/opensearch-java
Issue simili
-
bug web-server
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
jooby-project/jooby#4035 ·
I maintainer di solito rispondono entro 1 giorno
-
L: javascript
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
dependabot/dependabot-core#16744 ·
I maintainer di solito rispondono entro 1 giorno
-
intake mcp-intake needs-human-review priority:high type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Ikalus1988/MisakaNet#3987 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
quarkiverse/quarkus-google-cloud-services#1187 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
locationtech/jts#1250 ·