jackson-dataformats-text icon indicating copy to clipboard operation
jackson-dataformats-text copied to clipboard

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

Open guillermocalvo opened this issue 5 years ago • 1 comments

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:

  1. Create a YAML decoder:
public class YamlDecoder extends AbstractJackson2Decoder {
    public YamlDecoder() {
        super(new YAMLMapper(), MediaType.valueOf("application/x-yaml"));
    }
}
  1. Add it as a custom decoder:
@EnableWebFlux
public class AppConfiguration implements WebFluxConfigurer {
    ...
    @Override
    public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
        configurer.customCodecs().decoder(new YamlDecoder());
    }
}
  1. 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) {
        ...
    }
}
  1. Send a YAML request. Then an UnsupportedOperationException will be thrown from JsonFactory with the message:
Non-blocking source not (yet?) supported for this format (YAML)

guillermocalvo avatar Nov 22 '19 02:11 guillermocalvo

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. :)

cowtowncoder avatar Nov 22 '19 20:11 cowtowncoder