diff --git a/README.md b/README.md index 963261e..e00da0b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ repositories { } dependencies { - api("org.radarbase:radar-jersey:0.2.2") + api("org.radarbase:radar-jersey:0.2.2.1") } ``` diff --git a/build.gradle b/build.gradle index d9f149b..0e3b0a8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { description = 'Library for Jersey authorization, exception handling and configuration with the RADAR platform' group = 'org.radarbase' -version = '0.2.2' +version = '0.2.2.1' ext { githubRepoName = 'RADAR-base/radar-jersey' @@ -52,7 +52,7 @@ dependencies { runtimeOnly("org.glassfish.jersey.media:jersey-media-json-jackson:$jerseyVersion") - runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion") runtimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion") runtimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:$jacksonVersion") diff --git a/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt b/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt index 2d95248..b53a8fd 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt @@ -2,6 +2,7 @@ package org.radarbase.jersey.config import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import com.fasterxml.jackson.module.kotlin.KotlinModule import org.glassfish.jersey.internal.inject.AbstractBinder import org.glassfish.jersey.server.ResourceConfig import org.radarbase.jersey.auth.AuthConfig @@ -33,7 +34,8 @@ object ConfigLoader { return createResourceConfig(enhancerFactory.createEnhancers()) } - fun loadConfig(fileName: String, args: Array, clazz: Class): T { + @JvmOverloads + fun loadConfig(fileName: String, args: Array, clazz: Class, mapper: ObjectMapper? = null): T { val configFileName = when { args.size == 1 -> args[0] Files.exists(Paths.get(fileName)) -> fileName @@ -44,8 +46,9 @@ object ConfigLoader { val configFile = File(configFileName) logger.info("Reading configuration from ${configFile.absolutePath}") try { - val mapper = ObjectMapper(YAMLFactory()) - return mapper.readValue(configFile, clazz) + val localMapper = mapper ?: ObjectMapper(YAMLFactory()) + .registerModule(KotlinModule()) + return localMapper.readValue(configFile, clazz) } catch (ex: IOException) { logger.error("Usage: [$fileName]") logger.error("Failed to read config file $configFile: ${ex.message}") @@ -59,8 +62,8 @@ object ConfigLoader { * * @throws IllegalArgumentException if a file matching configFileName cannot be found */ - inline fun loadConfig(fileName: String, args: Array): T = - loadConfig(fileName, args, T::class.java) + inline fun loadConfig(fileName: String, args: Array, mapper: ObjectMapper? = null): T = + loadConfig(fileName, args, T::class.java, mapper) /** * Create a resourceConfig based on the provided resource enhancers. This method also disables