Skip to content

AbstractJackson2Decoder doesn't support decoding NDJSON arrays into Flux<List> #32579

Closed
@yuflyud

Description

@yuflyud

Affects: 6.1.5

I'm attempting to implement a Reactive RestController that accepts NDJSON (Newline Delimited JSON) where each row may contain a JSON array. An example of such NDJSON payload is as follows:

[{ "recordType":"Patient", "name":"John Doe"},{ "recordType":"Visit", "state":"complete"}]
[{ "recordType":"Practitioner", "name":"Stephen Smith"}]

The desired behavior is to transform the request body into a Flux<List<Record>>, where each emitted list corresponds to the JSON arrays within each row. However, the current implementation, which is completely expected according to the documentation, only produces a Flux<Record>.

Below is the endpoint code I would like to be supported:

  @PostMapping(value = "/submit", consumes = {MediaType.APPLICATION_NDJSON_VALUE},
      produces = MediaType.APPLICATION_JSON_VALUE)
  public Mono<Void> submit(@RequestBody Flux<List<Record>> rows) {
    return rows.log()
        .then();
  }

Upon investigation, I've identified that the issue lies within the AbstractJackson2Decoder class. Specifically, the tokenizeArrays parameter is set to true in the following line:

Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(processed, mapper.getFactory(), mapper, true,
        forceUseOfBigDecimal, getMaxInMemorySize());

This configuration causes the NDJSON payload with nested arrays to be tokenized in a way that produces Flux<Record> instead of the desired Flux<List<Record>>.
At present, I cannot find a straightforward way to modify this behavior without resorting to copying and altering the entire source code of the AbstractJackson2Decoder class.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions