FasterXML / FasterXML/jackson-dataformats-text

Add support for non-blocking ("async") YAML parsing

Offen
#165 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
yaml
Vorherrschende Sprache
Java
Sterne
455
Forks
164
Ø Merge
6 T. 10 Std.
Gemergte PRs (30 T.)
2

Beschreibung

Jackson-core supports [non-blocking parsers](http://fasterxml.github.io/jackson-core/javadoc/2.10/com/fasterxml/jackson/core/JsonFactory.html#createNonBlockingByteArrayParser--) since [version 2.9](http://fasterxml.github.io/jackson-core/javadoc/2.9/com/fasterxml/jackson/core/JsonFactory.html#createNonBlockingByteArrayParser--), but YAML doesn't seem to have a non-blocking parser yet.

This is preventing us from parsing YAML request bodies directly in reactive web apps (Spring WebFlux).

These are the steps to reproduce this problem:
1. Create a YAML decoder:
```java
public class YamlDecoder extends AbstractJackson2Decoder {
public YamlDecoder() {
super(new YAMLMapper(), MediaType.valueOf("application/x-yaml"));
}
}
```
2. Add it as a custom decoder:
```java
@EnableWebFlux
public class AppConfiguration implements WebFluxConfigurer {
...
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
configurer.customCodecs().decoder(new YamlDecoder());
}
}
```
3. Add a REST controller with a mapping that consumes YAML:
```java
@RestController
public class FoobarController {
@PostMapping(value = "/foo", consumes = "application/x-yaml")
public void foo(@RequestBody MyCustomClass body) {
...
}
}
```
4. Send a YAML request. Then an `UnsupportedOperationException` will be [thrown from `JsonFactory`](https://github.com/FasterXML/jackson-core/blob/2.11/src/main/java/com/fasterxml/jackson/core/JsonFactory.java#L1122) with the message:
```
Non-blocking source not (yet?) supported for this format (YAML)
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.