Skip to content

Commit

Permalink
Merge pull request #5 from RADAR-base/fix-kotlin-module-support
Browse files Browse the repository at this point in the history
Hotfix: Fix kotlin module support
  • Loading branch information
nivemaham authored Oct 23, 2019
2 parents 8450041 + ce80fb5 commit 64434f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}
dependencies {
api("org.radarbase:radar-jersey:0.2.2")
api("org.radarbase:radar-jersey:0.2.2.1")
}
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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")

Expand Down
13 changes: 8 additions & 5 deletions src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,7 +34,8 @@ object ConfigLoader {
return createResourceConfig(enhancerFactory.createEnhancers())
}

fun <T> loadConfig(fileName: String, args: Array<String>, clazz: Class<T>): T {
@JvmOverloads
fun <T> loadConfig(fileName: String, args: Array<String>, clazz: Class<T>, mapper: ObjectMapper? = null): T {
val configFileName = when {
args.size == 1 -> args[0]
Files.exists(Paths.get(fileName)) -> fileName
Expand All @@ -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: <command> [$fileName]")
logger.error("Failed to read config file $configFile: ${ex.message}")
Expand All @@ -59,8 +62,8 @@ object ConfigLoader {
*
* @throws IllegalArgumentException if a file matching configFileName cannot be found
*/
inline fun <reified T> loadConfig(fileName: String, args: Array<String>): T =
loadConfig(fileName, args, T::class.java)
inline fun <reified T> loadConfig(fileName: String, args: Array<String>, mapper: ObjectMapper? = null): T =
loadConfig(fileName, args, T::class.java, mapper)

/**
* Create a resourceConfig based on the provided resource enhancers. This method also disables
Expand Down

0 comments on commit 64434f4

Please sign in to comment.