Skip to content



This module holds utilities used in other libraries of the toolkit. Check the packages' documentation for more details. You can find a quick recap of the main features in the sections below.


The following code block shows the most common use cases for the Logger class:

val classLogger: Logger = Logger(Runtime::class) // Logger for the `Runtime` class
val instanceLogger: Logger = Logger(this) // Logger for this instance's class {
    You can add a quick log without declaring a Logger using 'com.hexagonkt.helpers.logger'.
    It is a default logger created for the System class (same as `Logger(System::class)`).

classLogger.trace { "Message only evaluated if trace enabled at ${}" }
classLogger.debug { "Message only evaluated if debug enabled at ${}" }
classLogger.warn { "Message only evaluated if warn enabled at ${}" } { "Message only evaluated if info enabled at ${}" }

val exception = IllegalStateException("Exception")
classLogger.warn(exception) { "Warning with exception" }
classLogger.error(exception) { "Error message with exception" }
classLogger.error { "Error without an exception" }

classLogger.time("Logs the time used to run the following block of code") {
    val message = "Block of code to be timed"

instanceLogger.flare { "Prints a log that stands out for ease searching" }

Dependency injection

You can take advantage of dependency injection using the InjectionManager object.

Check this sample to bind constructor functions or objects to classes, and inject them later:

// Bind classes to functions (create a different instance with each `inject` call)
InjectionManager.bind<Date> { java.sql.Date(System.currentTimeMillis()) }

// Bind classes to objects (returns the same instance for all `inject` calls)

// You can use labels to inject different instances
InjectionManager.bind<Date>("+1h") { java.sql.Date(System.currentTimeMillis() + 3_600_000) }
InjectionManager.bindObject<String>("toolkit", "Hexagon")

val currentSqlDate = InjectionManager.inject<Date>()
val currentSqlDateInferredType: Date = InjectionManager.inject()

// Inject different values for a class using tags (can be any type, not only string)
val nextHourSqlDate: Date = InjectionManager.inject("+1h")
val nextHourSqlDateInferredType: Date = InjectionManager.inject("+1h")

// Injecting classes bound to objects return always the same instance
val defaultString = InjectionManager.inject<String>()
val taggedString: String = InjectionManager.inject("toolkit")


The core module has utilities to serialize/parse data classes to JSON and YAML. Read the following snippet for details:

val jason = Person("Jason", "Jackson", LocalDate.of(1989, 12, 31))

val jasonJson = jason.serialize(Json) // Can also be Yaml or an string: "application/json"
val parsedJason = jasonJson.parse(Person::class)

assert(jason == parsedJason)
assert(jason !== parsedJason)



Name Summary
com.hexagonkt.helpers JVM information, a logger class and other useful utilities.
com.hexagonkt.http HTTP code shared between clients and servers and independent of third party libraries.
com.hexagonkt.injection Utilities to bind classes to creation closures or instances, and inject instances of those classes later.
com.hexagonkt.serialization Parse/serialize data in different formats to class instances.
com.hexagonkt.settings Load settings from different data sources and formats.


All Types