FasterXML / FasterXML/jackson-core
Can't tell non-blocking parser what charset to use for decoding input
- 主要语言
- Java
- 星标
- 2.4k
- 派生
- 928
- 平均合并
- 2 天 18 小时
- 30 天内合并 PR
- 24
描述
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`.
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。