Why would using writeValue stop a Flux but writing to a temporary value then printing it allow it to work?

16 views Asked by At

I have a Flux that has a doOnNext(this::dumpJson) but for some odd reason it stops on the first one if I do this

private void dumpJson(Object it) {
  try {
    objectMapper.writerWithDefaultPrettyPrinter().writeValue(System.out, it);
    System.out.flush();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

But if I convert to a String then write it out afterwards it works.

private void dumpJson(Object it) {
  try {
    final var s = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(it);
    System.out.println(s);
  } catch (JsonProcessingException e) {
    throw new RuntimeException(e);
  }
}
0

There are 0 answers