diff --git a/build.sbt b/build.sbt index 17e7884..0d4bced 100644 --- a/build.sbt +++ b/build.sbt @@ -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 ) ) @@ -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 diff --git a/pekko-http-jackson/src/main/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupport.scala b/pekko-http-jackson/src/main/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupport.scala index 4583830..a9beaa5 100644 --- a/pekko-http-jackson/src/main/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupport.scala +++ b/pekko-http-jackson/src/main/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupport.scala @@ -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 } diff --git a/pekko-http-jackson/src/test/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupportSpec.scala b/pekko-http-jackson/src/test/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupportSpec.scala index 852226b..1e68fe9 100644 --- a/pekko-http-jackson/src/test/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupportSpec.scala +++ b/pekko-http-jackson/src/test/scala/com/github/pjfanning/pekkohttpjackson/JacksonSupportSpec.scala @@ -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() = {