jackson-dataformats-text
jackson-dataformats-text copied to clipboard
Add support for non-blocking ("async") YAML parsing
Jackson-core supports non-blocking parsers since version 2.9, 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:
- Create a YAML decoder:
public class YamlDecoder extends AbstractJackson2Decoder {
public YamlDecoder() {
super(new YAMLMapper(), MediaType.valueOf("application/x-yaml"));
}
}
- Add it as a custom decoder:
@EnableWebFlux
public class AppConfiguration implements WebFluxConfigurer {
...
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
configurer.customCodecs().decoder(new YamlDecoder());
}
}
- Add a REST controller with a mapping that consumes YAML:
@RestController
public class FoobarController {
@PostMapping(value = "/foo", consumes = "application/x-yaml")
public void foo(@RequestBody MyCustomClass body) {
...
}
}
- Send a YAML request. Then an
UnsupportedOperationException
will be thrown fromJsonFactory
with the message:
Non-blocking source not (yet?) supported for this format (YAML)
True, non-blocking handling has so far only been implemented for JSON and Smile backends.
Of other backends, CBOR should be quite easy, and XML plausible with aalto-xml
.
But the challenge with YAML is that this would require SnakeYAML to support it, and then format module could use it.
So: if anyone has time and interest to work on this, it'd be interesting challenge. :)