FasterXML / FasterXML/jackson-core

Can't tell non-blocking parser what charset to use for decoding input

Ouverte
#596 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
documentation
Langage dominant
Java
Étoiles
2.4k
Forks
928
Merge moyen
2 j 18 h
PR mergées (30 j)
24

Description

I'm using Jackson's non-blocking parser to implement a `BodySubscriber` for use with Java's non-blocking HTTP client. The parser is created by `JsonFactory#createNonBlockingByteArrayParser()` using the factory instance associated with the `ObjectMapper` . It's working like a charm, but it seems that it uses `UTF-8` by default and there is no way of telling it other encodings to use (such as the encoding specified by the response headers other than `UTF-8`).

I figured it might auto-detect the response body's encoding like it's the case with other parsers, but it turned out that it assumes all input is `UTF-8`. For example, this snippet would crash:
```java
ObjectMapper mapper = new JsonMapper();
byte[] jsonBytes = "{\"Psst!\": \"I'm not UTF-8\"}".getBytes(StandardCharsets.UTF_16);
JsonParser asyncParser = mapper.getFactory().createNonBlockingByteArrayParser();
ByteArrayFeeder feeder = ((ByteArrayFeeder) asyncParser.getNonBlockingInputFeeder());
feeder.feedInput(jsonBytes, 0, jsonBytes.length);
feeder.endOfInput();
Map map = mapper.readValue(asyncParser, new TypeReference<>() {});
System.out.println(map);
```
It works fine if the JSON string is encoded with `UTF-8`.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.