This includes most common Java types, however additional instances can be registered simply be creating beans of type TypeConverter
.
@Get("/headerInferred")
String headerInferred(@Header String contentType) {
// ...
}
@Get("/headerInferred")
fun headerInferred(@Header contentType: String): String {
// ...
}
In this case if the HTTP header Content-Type
is not present in the request the route is considered invalid, since it cannot be satisfied and a HTTP 400 BAD REQUEST
is returned.
String headerNullable(@Nullable @Header String contentType) {
}
@Get("/headerNullable")
fun headerNullable(@Header contentType: String?): String? {
// ...
}
An null string will be passed if the header is absent from the request.
@Get("/date")
String date(@Header ZonedDateTime date) {
// ...
String dateFormat(@Format("dd/MM/yyyy hh:mm:ss a z") @Header ZonedDateTime date) {
// ...
}
@Get("/date")
fun date(@Header date: ZonedDateTime): String {
// ...
}
@Get("/dateFormat")
fun dateFormat(@Format("dd/MM/yyyy hh:mm:ss a z") @Header date: ZonedDateTime): String {
}