avaje / avaje-jex

Web routing for the JDK Http server
Apache License 2.0
23 stars 1 forks source link

Expose Context.outputStream() such that outputStream can be used directly #109

Closed rbygrave closed 2 days ago

rbygrave commented 2 days ago

For example, with Jsonb we can obtain the specific type once and then write directly to the outputSteam like:

ctx.status(200).contentType("application/json");
var result = HelloDto.rob();
jsonTypeHelloDto.toJson(result, ctx.outputStream());

... where jsonTypeHelloDto is obtained like:

static final Jsonb jsonb = Jsonb.builder().build();
static final JsonType<HelloDto> jsonTypeHelloDto = jsonb.type(HelloDto.class);

With this approach, it effectively bypasses the underlying io.avaje.jex.spi.JsonService with the view that this can be more flexible and more efficient.