Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions serialization-jackson/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ pekko.serialization.jackson {
max-number-length = 1000
max-string-length = 20000000
max-name-length = 50000
# max-document-length of -1 means unlimited
max-document-length = -1
# max-token-count of -1 means unlimited
max-token-count = -1
# max-document-length of `unlimited` (or a negative number such as -1) means unlimited
max-document-length = unlimited
# max-token-count of `unlimited` (or a negative number such as -1) means unlimited
max-token-count = unlimited
}

write {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ object JacksonObjectMapperProvider extends ExtensionId[JacksonObjectMapperProvid
baseConf
}

// "unlimited" is accepted as a synonym for -1 in the constraints that treat -1 as no limit
private def getLongOrUnlimited(config: Config, path: String): Long =
if (config.getString(path) == "unlimited") -1L
else config.getLong(path)

private def createJsonFactory(
bindingName: String,
objectMapperFactory: JacksonObjectMapperFactory,
Expand All @@ -93,8 +98,8 @@ object JacksonObjectMapperProvider extends ExtensionId[JacksonObjectMapperProvid
.maxNumberLength(config.getInt("read.max-number-length"))
.maxStringLength(config.getInt("read.max-string-length"))
.maxNameLength(config.getInt("read.max-name-length"))
.maxDocumentLength(config.getLong("read.max-document-length"))
.maxTokenCount(config.getLong("read.max-token-count"))
.maxDocumentLength(getLongOrUnlimited(config, "read.max-document-length"))
.maxTokenCount(getLongOrUnlimited(config, "read.max-token-count"))
.build()

val streamWriteConstraints = StreamWriteConstraints.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ class JacksonFactorySpec extends TestKit(ActorSystem("JacksonFactorySpec"))
streamReadConstraints.getMaxTokenCount shouldEqual maxTokenCount
}

"support unlimited as a StreamReadConstraints value" in {
val bindingName = "testJackson"
val config = ConfigFactory.parseString(
s"""pekko.serialization.jackson.read.max-document-length=unlimited
|pekko.serialization.jackson.read.max-token-count=unlimited
|""".stripMargin)
.withFallback(defaultConfig)
val jacksonConfig = JacksonObjectMapperProvider.configForBinding(bindingName, config)
val mapper = JacksonObjectMapperProvider.createObjectMapper(
bindingName, None, objectMapperFactory, jacksonConfig, dynamicAccess, None)
val streamReadConstraints = mapper.getFactory.streamReadConstraints()
streamReadConstraints.getMaxDocumentLength shouldEqual -1L
streamReadConstraints.getMaxTokenCount shouldEqual -1L
}

"support StreamWriteConstraints" in {
val bindingName = "testJackson"
val maxNestingDepth = 54321
Expand Down
8 changes: 4 additions & 4 deletions serialization-jackson3/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ pekko.serialization.jackson3 {
max-number-length = 1000
max-string-length = 20000000
max-name-length = 50000
# max-document-length of -1 means unlimited
max-document-length = -1
# max-token-count of -1 means unlimited
max-token-count = -1
# max-document-length of `unlimited` (or a negative number such as -1) means unlimited
max-document-length = unlimited
# max-token-count of `unlimited` (or a negative number such as -1) means unlimited
max-token-count = unlimited
}

write {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ object JacksonObjectMapperProvider extends ExtensionId[JacksonObjectMapperProvid
baseConf
}

// "unlimited" is accepted as a synonym for -1 in the constraints that treat -1 as no limit
private def getLongOrUnlimited(config: Config, path: String): Long =
if (config.getString(path) == "unlimited") -1L
else config.getLong(path)

private[pekko] def createJsonFactory(
bindingName: String,
objectMapperFactory: JacksonObjectMapperFactory,
Expand All @@ -86,8 +91,8 @@ object JacksonObjectMapperProvider extends ExtensionId[JacksonObjectMapperProvid
.maxNumberLength(config.getInt("read.max-number-length"))
.maxStringLength(config.getInt("read.max-string-length"))
.maxNameLength(config.getInt("read.max-name-length"))
.maxDocumentLength(config.getLong("read.max-document-length"))
.maxTokenCount(config.getLong("read.max-token-count"))
.maxDocumentLength(getLongOrUnlimited(config, "read.max-document-length"))
.maxTokenCount(getLongOrUnlimited(config, "read.max-token-count"))
.build()

val streamWriteConstraints = StreamWriteConstraints.builder()
Expand Down Expand Up @@ -159,7 +164,7 @@ object JacksonObjectMapperProvider extends ExtensionId[JacksonObjectMapperProvid
.maxNumberLength(config.getInt("read.max-number-length"))
.maxStringLength(config.getInt("read.max-string-length"))
.maxNameLength(config.getInt("read.max-name-length"))
.maxDocumentLength(config.getLong("read.max-document-length"))
.maxDocumentLength(getLongOrUnlimited(config, "read.max-document-length"))
.build()

val streamWriteConstraints = StreamWriteConstraints.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ class JacksonFactorySpec extends TestKit(ActorSystem("JacksonFactorySpec"))
streamReadConstraints.getMaxTokenCount shouldEqual maxTokenCount
}

"support unlimited as a StreamReadConstraints value" in {
val bindingName = "testJackson"
val config = ConfigFactory.parseString(
s"""pekko.serialization.jackson3.read.max-document-length=unlimited
|pekko.serialization.jackson3.read.max-token-count=unlimited
|""".stripMargin)
.withFallback(defaultConfig)
val jacksonConfig = JacksonObjectMapperProvider.configForBinding(bindingName, config)
val factory = JacksonObjectMapperProvider.createJsonFactory(
bindingName, objectMapperFactory, jacksonConfig, None)
val streamReadConstraints = factory.streamReadConstraints()
streamReadConstraints.getMaxDocumentLength shouldEqual -1L
streamReadConstraints.getMaxTokenCount shouldEqual -1L
}

"support StreamWriteConstraints" in {
val bindingName = "testJackson"
val maxNestingDepth = 54321
Expand Down