Skip to content

Commit

Permalink
Jackson3 support (#92)
Browse files Browse the repository at this point in the history
* Update build.sbt

* wip

* more changes

* Update Jackson.java

* Update Jackson.java

* temp fix for test

* Update JacksonSupportSpec.scala

* Update JacksonSupport.scala

* Update reference.conf

* Update build.sbt
  • Loading branch information
pjfanning authored Mar 8, 2025
1 parent 19c22c1 commit 5b2f139
Show file tree
Hide file tree
Showing 6 changed files with 641 additions and 19 deletions.
53 changes: 34 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ lazy val `pekko-http-json` =
`pekko-http-avro4s`,
`pekko-http-circe`,
`pekko-http-jackson`,
`pekko-http-jackson3`,
`pekko-http-json4s`,
`pekko-http-jsoniter-scala`,
`pekko-http-ninny`,
Expand Down Expand Up @@ -107,10 +108,22 @@ lazy val `pekko-http-jackson` =
.settings(
libraryDependencies ++= Seq(
library.pekkoHttp,
library.jacksonModuleScala,
library.pekkoStream % Provided,
library.scalaTest % Test,
library.jacksonModuleParamNames % Test
library.jacksonModuleScala2,
library.pekkoStream % Provided,
library.scalaTest % Test,
library.jacksonModuleParamNames2 % Test
)
)

lazy val `pekko-http-jackson3` =
project
.settings(commonSettings, withScala3)
.settings(
libraryDependencies ++= Seq(
library.pekkoHttp,
library.jacksonModuleScala3,
library.pekkoStream % Provided,
library.scalaTest % Test
)
)

Expand Down Expand Up @@ -221,19 +234,20 @@ lazy val commonSettings =
lazy val library =
new {
object Version {
val pekko = "1.1.3"
val pekkoHttp = "1.1.0"
val argonaut = "6.3.11"
val avro4s = "4.1.2"
val circe = "0.14.10"
val jacksonModuleScala = "2.18.3"
val json4s = "4.0.7"
val jsoniterScala = "2.33.2"
val ninny = "0.9.1"
val play = "3.0.4"
val scalaTest = "3.2.19"
val upickle = "4.1.0"
val zioJson = "0.7.36"
val pekko = "1.1.3"
val pekkoHttp = "1.1.0"
val argonaut = "6.3.11"
val avro4s = "4.1.2"
val circe = "0.14.10"
val jackson2 = "2.18.3"
val jackson3 = "3.0.0-rc1"
val json4s = "4.0.7"
val jsoniterScala = "2.33.2"
val ninny = "0.9.1"
val play = "3.0.4"
val scalaTest = "3.2.19"
val upickle = "4.1.0"
val zioJson = "0.7.36"
}
// format: off
val pekkoHttp = "org.apache.pekko" %% "pekko-http" % Version.pekkoHttp
Expand All @@ -243,8 +257,9 @@ lazy val library =
val circe = "io.circe" %% "circe-core" % Version.circe
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 jacksonModuleScala2 = "com.fasterxml.jackson.module" %% "jackson-module-scala" % Version.jackson2
val jacksonModuleParamNames2 = "com.fasterxml.jackson.module" % "jackson-module-parameter-names" % Version.jackson2
val jacksonModuleScala3 = "tools.jackson.module" %% "jackson-module-scala" % Version.jackson3
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
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/

/*
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
*/

package com.github.pjfanning.pekkohttpjackson3;

import org.apache.pekko.http.javadsl.model.MediaTypes;
import org.apache.pekko.http.javadsl.model.RequestEntity;
import org.apache.pekko.http.javadsl.marshalling.Marshaller;

import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;

final class Jackson {

static <T> Marshaller<T, RequestEntity> marshaller(ObjectMapper mapper) {
return Marshaller.wrapEntity(
u -> toJSON(mapper, u), Marshaller.stringToEntity(), MediaTypes.APPLICATION_JSON);
}

private static String toJSON(ObjectMapper mapper, Object object) {
try {
return mapper.writeValueAsString(object);
} catch (JacksonException e) {
throw new IllegalArgumentException("Cannot marshal to JSON: " + object, e);
}
}

private Jackson() {}
}
41 changes: 41 additions & 0 deletions pekko-http-jackson3/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pekko-http-json {
jackson {
jackson-modules += "tools.jackson.module.scala.DefaultScalaModule"
read {
# see https://www.javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.18.0/com/fasterxml/jackson/core/StreamReadConstraints.html
# these defaults are the same as the defaults in `StreamReadConstraints`
max-nesting-depth = 1000
max-number-length = 1000
max-string-length = 20000000
# added in jackson 2.16.0
max-name-length = 50000
# max-document-length of -1 means unlimited (since jackson 2.16.0)
max-document-length = -1
# max-token-count of -1 means unlimited (since jackson 2.18.0)
max-token-count = -1

# see https://www.javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.18.0/com/fasterxml/jackson/core/StreamReadFeature.html
# these defaults are the same as the defaults in `StreamReadFeature`
feature {
include-source-in-location = false
}
}
write {
# see https://www.javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.18.0/com/fasterxml/jackson/core/StreamWriteConstraints.html
# these defaults are the same as the defaults in `StreamWriteConstraints`
max-nesting-depth = 1000
}

# Controls the Buffer Recycler Pool implementation used by Jackson.
# https://javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.18.0/com/fasterxml/jackson/core/util/JsonRecyclerPools.html
# The default is "thread-local" which is the same as the default in Jackson 2.16.
buffer-recycler {
# the supported values are "thread-local", "concurrent-deque", "shared-concurrent-deque", "bounded", "non-recycling"
# "lock-free", "shared-lock-free" are supported but not recommended as they are due for removal in Jackson
pool-instance = "thread-local"
# the maximum size of bounded recycler pools - must be >=1 or an IllegalArgumentException will occur
# only applies to pool-instance type "bounded"
bounded-pool-size = 100
}
}
}
Loading

0 comments on commit 5b2f139

Please sign in to comment.