Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG] jackson3 JacksonJsonpMapper(ObjectMapper) fails to deserialize `_source` with "Trailing token" error

Chiusa Adatta ai principianti
#2,236 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@junyeokk ci sta già lavorando.

Dal 26/10/2026.

  • #2237 di @junyeokk — aperta

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

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

bug untriaged
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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di opensearch-project/opensearch-java

Tutte le issue di opensearch-project/opensearch-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.