-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
6 changed files
with
641 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
pekko-http-jackson3/src/main/java/com/github/pjfanning/pekkohttpjackson3/Jackson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.