Skip to content

Commit aa14ab6

Browse files
committed
WIP - jackson 3
1 parent 97899f5 commit aa14ab6

File tree

16 files changed

+151
-129
lines changed

16 files changed

+151
-129
lines changed

build.sbt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ lazy val clientesjava = (project in file("elastic4s-client-esjava"))
176176
libraryDependencies ++= Seq(
177177
elasticsearchRestClient,
178178
log4jApi,
179-
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
180-
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
181-
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude (
179+
fasterXmlJacksonCore,
180+
fasterXmlJacksonDatabind,
181+
fasterXmlJacksonModuleScala exclude (
182182
"org.scala-lang",
183183
"scala-library"
184184
)
@@ -262,11 +262,13 @@ lazy val jackson = (project in file("elastic4s-json-jackson"))
262262
.settings(name := "elastic4s-json-jackson")
263263
.settings(scala3Settings)
264264
.settings(
265-
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
266-
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
267-
libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude (
268-
"org.scala-lang",
269-
"scala-library"
265+
libraryDependencies ++= Seq(
266+
fasterXmlJacksonCore,
267+
fasterXmlJacksonDatabind,
268+
fasterXmlJacksonModuleScala exclude (
269+
"org.scala-lang",
270+
"scala-library"
271+
)
270272
)
271273
)
272274

@@ -341,15 +343,15 @@ lazy val tests = (project in file("elastic4s-tests"))
341343
libraryDependencies ++= Seq(
342344
commonsIo,
343345
mockitoCore,
344-
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion % Test,
345-
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion % Test,
346-
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion % Test exclude (
346+
fasterXmlJacksonCore % Test,
347+
fasterXmlJacksonDatabind % Test,
348+
fasterXmlJacksonModuleScala % Test exclude (
347349
"org.scala-lang",
348350
"scala-library"
349351
),
350-
"org.apache.logging.log4j" % "log4j-api" % "2.25.2" % Test,
351-
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.25.2" % Test,
352-
"org.apache.logging.log4j" % "log4j-core" % "2.25.2" % Test
352+
"org.apache.logging.log4j" % "log4j-api" % "2.25.2" % Test,
353+
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.25.2" % Test,
354+
"org.apache.logging.log4j" % "log4j-core" % "2.25.2" % Test
353355
),
354356
Test / fork := false,
355357
Test / parallelExecution := false,

elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/searches/SearchHandlers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait SearchHandlers {
2929
val json = JacksonSupport.mapper.readTree(response.entity.get.content)
3030
val items = Option(json.get("responses")) match {
3131
case Some(node) =>
32-
node.elements
32+
node.values
3333
.asScala
3434
.zipWithIndex
3535
.map {

elastic4s-core/src/test/scala/com/sksamuel/elastic4s/JsonSugar.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package com.sksamuel.elastic4s
22

3-
import com.fasterxml.jackson.databind.ObjectMapper
4-
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
3+
import com.fasterxml.jackson.annotation.JsonInclude
4+
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
5+
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
56
import org.scalatest.matchers.should.Matchers
67
import org.scalatest.matchers.{MatchResult, Matcher}
8+
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
9+
import tools.jackson.databind.json.JsonMapper
710

811
trait JsonSugar extends Matchers {
9-
10-
private val mapper = new ObjectMapper with ClassTagExtensions
11-
mapper.registerModule(DefaultScalaModule)
12+
private val mapper: ObjectMapper with ClassTagExtensions =
13+
JsonMapper.builder(JsonFactory.builder().build())
14+
.addModule(DefaultScalaModule)
15+
.build() :: ClassTagExtensions
1216

1317
def matchJsonResource(resourceName: String) = new JsonResourceMatcher(resourceName)
1418

@@ -38,7 +42,7 @@ trait JsonSugar extends Matchers {
3842
jsonResource should not be null
3943
}
4044

41-
val expectedJson = mapper.readTree(jsonResource)
45+
val expectedJson = mapper.readTree(jsonResource.openStream())
4246
val actualJson = mapper.readTree(left)
4347

4448
MatchResult(
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package com.sksamuel.elastic4s.requests.searches.aggs.responses
22

33
import com.fasterxml.jackson.annotation.JsonInclude
4-
import com.fasterxml.jackson.core.JsonParser
5-
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
6-
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
4+
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
5+
import tools.jackson.databind.json.JsonMapper
6+
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
7+
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
78

89
object JacksonSupport {
9-
10-
val mapper: ObjectMapper with ClassTagExtensions = new ObjectMapper with ClassTagExtensions
11-
mapper.registerModule(DefaultScalaModule)
12-
13-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
14-
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
15-
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
16-
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
17-
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
18-
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
10+
val mapper: ObjectMapper with ClassTagExtensions = {
11+
val jf = JsonFactory.builder()
12+
.enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES)
13+
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
14+
.build();
15+
JsonMapper.builder(jf)
16+
.addModule(DefaultScalaModule)
17+
.changeDefaultPropertyInclusion(_.withValueInclusion(JsonInclude.Include.NON_NULL))
18+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
19+
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
20+
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
21+
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
22+
.build() :: ClassTagExtensions
23+
}
1924
}

elastic4s-handlers/src/main/scala/com/sksamuel/elastic4s/Handler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.sksamuel.elastic4s
22

3-
import com.fasterxml.jackson.module.scala.JavaTypeable
3+
import tools.jackson.module.scala.JavaTypeable
44
import org.slf4j.{Logger, LoggerFactory}
55

66
/** A [[Handler]] is a typeclass used to create [[ElasticRequest]] instances from elastic4s models, which are the sent

elastic4s-handlers/src/main/scala/com/sksamuel/elastic4s/ResponseHandler.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.sksamuel.elastic4s
22

3-
import com.fasterxml.jackson.databind.JsonNode
4-
import com.fasterxml.jackson.databind.`type`.TypeFactory
5-
import com.fasterxml.jackson.module.scala.JavaTypeable
3+
import tools.jackson.databind.JsonNode
4+
import tools.jackson.databind.`type`.TypeFactory
5+
import tools.jackson.module.scala.JavaTypeable
66
import com.sksamuel.elastic4s.handlers.ElasticErrorParser
77
import com.sksamuel.elastic4s.ext.OptionImplicits.RichOption
88
import org.slf4j.{Logger, LoggerFactory}
@@ -31,7 +31,7 @@ object ResponseHandler {
3131

3232
def fromNode[U: JavaTypeable](node: JsonNode): U = {
3333
logger.debug(
34-
s"Attempting to unmarshall json node to ${implicitly[JavaTypeable[U]].asJavaType(TypeFactory.defaultInstance).getRawClass.getName}"
34+
s"Attempting to unmarshall json node to ${implicitly[JavaTypeable[U]].asJavaType(TypeFactory.createDefaultInstance()).getRawClass.getName}"
3535
)
3636
JacksonSupport.mapper.readValue[U](JacksonSupport.mapper.writeValueAsBytes(node))
3737
}
@@ -41,7 +41,7 @@ object ResponseHandler {
4141

4242
def fromEntity[U: JavaTypeable](entity: HttpEntity.StringEntity): U = {
4343
logger.debug(
44-
s"Attempting to unmarshall response to ${implicitly[JavaTypeable[U]].asJavaType(TypeFactory.defaultInstance).getRawClass.getName}"
44+
s"Attempting to unmarshall response to ${implicitly[JavaTypeable[U]].asJavaType(TypeFactory.createDefaultInstance()).getRawClass.getName}"
4545
)
4646
logger.debug(entity.content)
4747
JacksonSupport.mapper.readValue[U](entity.content)
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package com.sksamuel.elastic4s.handlers
22

33
import com.fasterxml.jackson.annotation.JsonInclude
4-
import com.fasterxml.jackson.core.JsonParser
5-
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
6-
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
4+
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
5+
import tools.jackson.databind.json.JsonMapper
6+
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
7+
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
78

89
object JacksonSupport {
9-
10-
val mapper: ObjectMapper with ClassTagExtensions = new ObjectMapper with ClassTagExtensions
11-
mapper.registerModule(DefaultScalaModule)
12-
13-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
14-
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
15-
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
16-
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
17-
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
18-
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
10+
val mapper: ObjectMapper with ClassTagExtensions = {
11+
val jf = JsonFactory.builder()
12+
.enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES)
13+
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
14+
.build();
15+
JsonMapper.builder(jf)
16+
.addModule(DefaultScalaModule)
17+
.changeDefaultPropertyInclusion(_.withValueInclusion(JsonInclude.Include.NON_NULL))
18+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
19+
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
20+
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
21+
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
22+
.build() :: ClassTagExtensions
23+
}
1924
}

elastic4s-handlers/src/main/scala/com/sksamuel/elastic4s/handlers/alias/IndexAliasHandlers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait IndexAliasHandlers {
2121
case 200 =>
2222
val root = ResponseHandler.json(response.entity.get)
2323
val map = root.properties.asScala.toVector.map { entry =>
24-
Index(entry.getKey) -> entry.getValue.get("aliases").fieldNames.asScala.toList.map(Alias.apply)
24+
Index(entry.getKey) -> entry.getValue.get("aliases").propertyNames.asScala.toList.map(Alias.apply)
2525
}.toMap
2626
Right(IndexAliases(map))
2727
case 404 => Right(IndexAliases(Map.empty))

elastic4s-handlers/src/main/scala/com/sksamuel/elastic4s/handlers/get/GetHandlers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.sksamuel.elastic4s.handlers.get
22

3-
import com.fasterxml.jackson.databind.JsonNode
3+
import tools.jackson.databind.JsonNode
44
import com.sksamuel.elastic4s.handlers.common.FetchSourceContextQueryParameterFn
55
import com.sksamuel.elastic4s.handlers.{ElasticErrorParser, VersionTypeHttpString}
66
import com.sksamuel.elastic4s.requests.get.{GetRequest, GetResponse, MultiGetRequest, MultiGetResponse}
Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
package com.sksamuel.elastic4s
22

33
import com.fasterxml.jackson.annotation.JsonInclude
4-
import com.fasterxml.jackson.core.JsonParser
5-
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
6-
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
4+
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
5+
import tools.jackson.databind.json.JsonMapper
6+
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
7+
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
78

89
object JacksonSupport {
9-
10-
val mapper: ObjectMapper with ClassTagExtensions = new ObjectMapper with ClassTagExtensions
11-
mapper.registerModule(DefaultScalaModule)
12-
13-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
14-
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
15-
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
16-
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
17-
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
18-
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
19-
20-
// class Deserializer(vc: Class[_]) extends StdDeserializer[Total](vc) {
21-
// override def deserialize(p: JsonParser, ctxt: DeserializationContext): Total = {
22-
// val node: JsonNode = p.getCodec.readTree(p)
23-
// if (node.isNumber) Total(node.toString.toLong, "eq")
24-
// else Total(node.findValue("value").asLong, node.findValue("relation").asText())
25-
// }
26-
// }
27-
//
28-
// val module = new SimpleModule {
29-
// addDeserializer(classOf[Total], new Total.Deserializer(classOf[Total]))
30-
// }
31-
// mapper.registerModule(module)
10+
val mapper: ObjectMapper with ClassTagExtensions = {
11+
val jf = JsonFactory.builder()
12+
.enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES)
13+
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
14+
.build();
15+
JsonMapper.builder(jf)
16+
.addModule(DefaultScalaModule)
17+
.changeDefaultPropertyInclusion(_.withValueInclusion(JsonInclude.Include.NON_NULL))
18+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
19+
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
20+
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
21+
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
22+
.build() :: ClassTagExtensions
23+
}
3224
}

0 commit comments

Comments
 (0)