Important: This news article covers an old version of Javalin (v5.3.0). The current version is v6.1.3.
See the documentation page for up-to-date information.
Happy 2023 🥳

New config options!

File upload config

Javalin uses standard servlet file upload handling to deal with multipart requests. This allows for configuring the maximum size for each individual file, the maximum size for the entire request, the maximum size of file to handle via in-memory upload and the cache directory to write uploaded files to if they exceed this limit.

All of these values can be configured through the file upload config as follows:

  • Java
  • Kotlin
Javalin.create(config -> {
    config.fileUpload.cacheDirectory("c:/temp"); //where to write files that exceed the in memory limit
    config.fileUpload.maxFileSize(100, SizeUnit.MB); //the maximum individual file size allowed
    config.fileUpload.maxInMemoryFileSize(10, SizeUnit.MB); //the maximum file size to handle in memory
    config.fileUpload.maxTotalRequestSize(1, SizeUnit.GB); //the maximum size of the entire multipart request
});
Javalin.create { config ->
    config.fileUpload.cacheDirectory("c:/temp") //where to write files that exceed the in memory limit
    config.fileUpload.maxFileSize(100, SizeUnit.MB) //the maximum individual file size allowed
    config.fileUpload.maxInMemoryFileSize(10, SizeUnit.MB) //the maximum file size to handle in memory
    config.fileUpload.maxTotalRequestSize(1, SizeUnit.GB) //the maximum size of the entire multipart request
}

FileRenderer now configurable per instance

  • Java
  • Kotlin
config.fileRenderer((filePath, model, context) -> "Rendered template");
config.fileRenderer { filePath, model, context -> "Rendered template" }

The default FileRenderer is the old JavalinRenderer singleton, so everything works just as before.

The different template engines are also loaded automatically now, so you no longer have to do, for example, JavalinJte.init(). You can if you want to though. Your choice.

JavalinJackson#updateMapper

  • Java
  • Kotlin
config.jsonMapper(new JavalinJackson().updateMapper(mapper -> {
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
});
config.jsonMapper(JavalinJackson().updateMapper { mapper ->
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
})

We’ve added a simple method for updating the JavalinJackson mapper. This makes it easier to configure the default mapper.

Other features

  • You can now get a map of all uploaded files using Context#uploadedFileMap. This will return a Map<String, List<UploadedFile>>.
  • You can now get or compute a request attribute through Context#attributeOrCompute.

Bugfixes

  • SeekableWriter now closes streams even when no range is specified
  • Each line is prefixed with data: when sending multi-line data over SSE