Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Mar 14, 2024
1 parent 815a3ad commit 4df7ad2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ lazy val `pekko-http-jackson` =
library.pekkoHttp,
library.pekkoHttpJacksonJava,
library.jacksonModuleScala,
library.pekkoStream % Provided,
library.scalaTest % Test,
library.pekkoStream % Provided,
library.scalaTest % Test,
library.jacksonModuleParamNames % Test
)
)

Expand Down Expand Up @@ -245,6 +246,7 @@ lazy val library =
val circeGeneric = "io.circe" %% "circe-generic" % Version.circe
val circeParser = "io.circe" %% "circe-parser" % Version.circe
val jacksonModuleScala = "com.fasterxml.jackson.module" %% "jackson-module-scala" % Version.jacksonModuleScala
val jacksonModuleParamNames = "com.fasterxml.jackson.module" % "jackson-module-parameter-names" % Version.jacksonModuleScala
val json4sCore = "org.json4s" %% "json4s-core" % Version.json4s
val json4sJackson = "org.json4s" %% "json4s-jackson" % Version.json4s
val json4sNative = "org.json4s" %% "json4s-native" % Version.json4s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ object JacksonSupport extends JacksonSupport {
case other => throw new IllegalArgumentException(s"Unknown recycler-pool: $other")
}

import org.apache.pekko.util.ccompat.JavaConverters._

private val configuredModules = jacksonConfig.getStringList("jackson-modules").asScala.toSeq
private val modules = configuredModules.map(loadModule)

val defaultObjectMapper: ObjectMapper with ClassTagExtensions = {
val builder = JsonMapper.builder(createJsonFactory(jacksonConfig))
val defaultObjectMapper: ObjectMapper with ClassTagExtensions = createObjectMapper(jacksonConfig)

private[pekkohttpjackson] def createObjectMapper(
config: Config
): ObjectMapper with ClassTagExtensions = {
val builder = JsonMapper.builder(createJsonFactory(config))
import org.apache.pekko.util.ccompat.JavaConverters._
val configuredModules = config.getStringList("jackson-modules").asScala.toSeq
val modules = configuredModules.map(loadModule)
modules.foreach(builder.addModule)
builder.build() :: ClassTagExtensions
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ final class JacksonSupportSpec extends AsyncWordSpec with Matchers with BeforeAn
.build()
.isEnabled(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION) shouldBe true
}

"support loading jackson-module-parameter-names" in {
val testCfg = ConfigFactory
.parseString(
"""jackson-modules += "com.fasterxml.jackson.module.paramnames.ParameterNamesModule""""
)
.withFallback(JacksonSupport.jacksonConfig)
.resolve()
val mapper = JacksonSupport.createObjectMapper(testCfg)
mapper.getRegisteredModuleIds should contain("jackson-module-parameter-names")
mapper.getRegisteredModuleIds should contain(
"com.fasterxml.jackson.module.scala.DefaultScalaModule"
)
}
}

override protected def afterAll() = {
Expand Down

0 comments on commit 4df7ad2

Please sign in to comment.