-
-
Notifications
You must be signed in to change notification settings - Fork 80
Kotlin
As of version 3.7, Configurate provides several extensions to improve integration with Kotlin
Some extension functions are provided which overload object indexing. This lets users access nodes with the syntax parent["path", "to", "child"], and even easily set values with parent["node"] = "hello"
To interact more easily with mapped types, there are extensions using reified type parameters to generate the appropriate type token: node.get<T>(default: T? = null) and node.set<T>(value: T)
The T.mapper() extension function allows accessing an ObjectMapper built for any object type, and the function objectMapper<T>() allows accessing object mappers constructed for a specific generic type on the default object mapper factory. ObjectMapperFactory.getMapper<T>() and TypeSerializerCollection.get<T>() both allow accessing their respective types by using generic types, rather than explicit TypeTokens.
While Configurate does not directly provide support for kotlinx.serialization, there is a community project at ItsDoot/configurate-serialization that can currently deserialize a node into a Kotlin Serializable object.
With Configurate v4's Publisher API used for file and value watchers, listeners are able to be converted into Kotlin's Flows for better integration with Kotlin's coroutine concurrency.