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
30 changes: 16 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ lazy val clientesjava = (project in file("elastic4s-client-esjava"))
libraryDependencies ++= Seq(
elasticsearchRestClient,
log4jApi,
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude (
fasterXmlJacksonCore,
fasterXmlJacksonDatabind,
fasterXmlJacksonModuleScala exclude (
"org.scala-lang",
"scala-library"
)
Expand Down Expand Up @@ -262,11 +262,13 @@ lazy val jackson = (project in file("elastic4s-json-jackson"))
.settings(name := "elastic4s-json-jackson")
.settings(scala3Settings)
.settings(
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion exclude (
"org.scala-lang",
"scala-library"
libraryDependencies ++= Seq(
fasterXmlJacksonCore,
fasterXmlJacksonDatabind,
fasterXmlJacksonModuleScala exclude (
"org.scala-lang",
"scala-library"
)
)
)

Expand Down Expand Up @@ -341,15 +343,15 @@ lazy val tests = (project in file("elastic4s-tests"))
libraryDependencies ++= Seq(
commonsIo,
mockitoCore,
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion % Test,
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion % Test,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion % Test exclude (
fasterXmlJacksonCore % Test,
fasterXmlJacksonDatabind % Test,
fasterXmlJacksonModuleScala % Test exclude (
"org.scala-lang",
"scala-library"
),
"org.apache.logging.log4j" % "log4j-api" % "2.25.2" % Test,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.25.2" % Test,
"org.apache.logging.log4j" % "log4j-core" % "2.25.2" % Test
"org.apache.logging.log4j" % "log4j-api" % "2.25.2" % Test,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.25.2" % Test,
"org.apache.logging.log4j" % "log4j-core" % "2.25.2" % Test
),
Test / fork := false,
Test / parallelExecution := false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait SearchHandlers {
val json = JacksonSupport.mapper.readTree(response.entity.get.content)
val items = Option(json.get("responses")) match {
case Some(node) =>
node.elements
node.values
.asScala
.zipWithIndex
.map {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.sksamuel.elastic4s

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
import com.fasterxml.jackson.annotation.JsonInclude
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
import org.scalatest.matchers.should.Matchers
import org.scalatest.matchers.{MatchResult, Matcher}
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
import tools.jackson.databind.json.JsonMapper

trait JsonSugar extends Matchers {

private val mapper = new ObjectMapper with ClassTagExtensions
mapper.registerModule(DefaultScalaModule)
private val mapper: ObjectMapper with ClassTagExtensions =
JsonMapper.builder(JsonFactory.builder().build())
.addModule(DefaultScalaModule)
.build() :: ClassTagExtensions

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

Expand Down Expand Up @@ -38,7 +42,7 @@ trait JsonSugar extends Matchers {
jsonResource should not be null
}

val expectedJson = mapper.readTree(jsonResource)
val expectedJson = mapper.readTree(jsonResource.openStream())
val actualJson = mapper.readTree(left)

MatchResult(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package com.sksamuel.elastic4s.requests.searches.aggs.responses

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
import tools.jackson.databind.json.JsonMapper
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}

object JacksonSupport {

val mapper: ObjectMapper with ClassTagExtensions = new ObjectMapper with ClassTagExtensions
mapper.registerModule(DefaultScalaModule)

mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
val mapper: ObjectMapper with ClassTagExtensions = {
val jf = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES)
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.build()
JsonMapper.builder(jf)
.addModule(DefaultScalaModule)
.changeDefaultPropertyInclusion(_.withValueInclusion(JsonInclude.Include.NON_NULL))
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
.build() :: ClassTagExtensions
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sksamuel.elastic4s

import com.fasterxml.jackson.module.scala.JavaTypeable
import tools.jackson.module.scala.JavaTypeable
import org.slf4j.{Logger, LoggerFactory}

/** A [[Handler]] is a typeclass used to create [[ElasticRequest]] instances from elastic4s models, which are the sent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.sksamuel.elastic4s

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.`type`.TypeFactory
import com.fasterxml.jackson.module.scala.JavaTypeable
import tools.jackson.databind.JsonNode
import tools.jackson.databind.`type`.TypeFactory
import tools.jackson.module.scala.JavaTypeable
import com.sksamuel.elastic4s.handlers.ElasticErrorParser
import com.sksamuel.elastic4s.ext.OptionImplicits.RichOption
import org.slf4j.{Logger, LoggerFactory}
Expand Down Expand Up @@ -31,7 +31,7 @@ object ResponseHandler {

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

def fromEntity[U: JavaTypeable](entity: HttpEntity.StringEntity): U = {
logger.debug(
s"Attempting to unmarshall response to ${implicitly[JavaTypeable[U]].asJavaType(TypeFactory.defaultInstance).getRawClass.getName}"
s"Attempting to unmarshall response to ${implicitly[JavaTypeable[U]].asJavaType(TypeFactory.createDefaultInstance()).getRawClass.getName}"
)
logger.debug(entity.content)
JacksonSupport.mapper.readValue[U](entity.content)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package com.sksamuel.elastic4s.handlers

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
import tools.jackson.databind.json.JsonMapper
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}

object JacksonSupport {

val mapper: ObjectMapper with ClassTagExtensions = new ObjectMapper with ClassTagExtensions
mapper.registerModule(DefaultScalaModule)

mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
val mapper: ObjectMapper with ClassTagExtensions = {
val jf = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES)
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.build()
JsonMapper.builder(jf)
.addModule(DefaultScalaModule)
.changeDefaultPropertyInclusion(_.withValueInclusion(JsonInclude.Include.NON_NULL))
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
.build() :: ClassTagExtensions
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait IndexAliasHandlers {
case 200 =>
val root = ResponseHandler.json(response.entity.get)
val map = root.properties.asScala.toVector.map { entry =>
Index(entry.getKey) -> entry.getValue.get("aliases").fieldNames.asScala.toList.map(Alias.apply)
Index(entry.getKey) -> entry.getValue.get("aliases").propertyNames.asScala.toList.map(Alias.apply)
}.toMap
Right(IndexAliases(map))
case 404 => Right(IndexAliases(Map.empty))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sksamuel.elastic4s.handlers.get

import com.fasterxml.jackson.databind.JsonNode
import tools.jackson.databind.JsonNode
import com.sksamuel.elastic4s.handlers.common.FetchSourceContextQueryParameterFn
import com.sksamuel.elastic4s.handlers.{ElasticErrorParser, VersionTypeHttpString}
import com.sksamuel.elastic4s.requests.get.{GetRequest, GetResponse, MultiGetRequest, MultiGetResponse}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
package com.sksamuel.elastic4s

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
import tools.jackson.databind.json.JsonMapper
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}

object JacksonSupport {

val mapper: ObjectMapper with ClassTagExtensions = new ObjectMapper with ClassTagExtensions
mapper.registerModule(DefaultScalaModule)

mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)

// class Deserializer(vc: Class[_]) extends StdDeserializer[Total](vc) {
// override def deserialize(p: JsonParser, ctxt: DeserializationContext): Total = {
// val node: JsonNode = p.getCodec.readTree(p)
// if (node.isNumber) Total(node.toString.toLong, "eq")
// else Total(node.findValue("value").asLong, node.findValue("relation").asText())
// }
// }
//
// val module = new SimpleModule {
// addDeserializer(classOf[Total], new Total.Deserializer(classOf[Total]))
// }
// mapper.registerModule(module)
val mapper: ObjectMapper with ClassTagExtensions = {
val jf = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES)
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.build()
JsonMapper.builder(jf)
.addModule(DefaultScalaModule)
.changeDefaultPropertyInclusion(_.withValueInclusion(JsonInclude.Include.NON_NULL))
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
.build() :: ClassTagExtensions
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.sksamuel.elastic4s.json

import com.fasterxml.jackson.databind.node.{
import tools.jackson.databind.node.{
BooleanNode,
DoubleNode,
FloatNode,
IntNode,
JsonNodeFactory,
LongNode,
NullNode,
TextNode
StringNode
}
import com.fasterxml.jackson.databind.{JsonNode, util}
import tools.jackson.databind.{JsonNode, util}
import com.sksamuel.elastic4s.JacksonSupport

trait JsonBuilder {
Expand Down Expand Up @@ -46,15 +46,15 @@ object JacksonBuilder extends JsonBuilder {
)
}
Left(node)
case StringValue(value) => Left(TextNode.valueOf(value))
case StringValue(value) => Left(StringNode.valueOf(value))
case LongValue(value) => Left(LongNode.valueOf(value))
case IntValue(value) => Left(IntNode.valueOf(value))
case FloatValue(value) => Left(FloatNode.valueOf(value))
case DoubleValue(value) => Left(DoubleNode.valueOf(value))
case BooleanValue(value) => Left(BooleanNode.valueOf(value))
case BigDecimalValue(value) => Left(JsonNodeFactory.instance.numberNode(value.underlying()))
case BigIntValue(value) => Left(JsonNodeFactory.instance.numberNode(value.underlying()))
case RawValue(value) => Right(new com.fasterxml.jackson.databind.util.RawValue(value))
case RawValue(value) => Right(new tools.jackson.databind.util.RawValue(value))
case NullValue => Left(NullNode.instance)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.sksamuel.elastic4s.jackson

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, JavaTypeable}
import tools.jackson.databind.ObjectMapper
import tools.jackson.databind.node.ObjectNode
import tools.jackson.module.scala.{ClassTagExtensions, JavaTypeable}
import com.sksamuel.elastic4s._
import org.slf4j.{Logger, LoggerFactory}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package com.sksamuel.elastic4s.jackson

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.std.NumberSerializers
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}
import tools.jackson.core.json.{JsonFactory, JsonReadFeature}
import tools.jackson.databind.json.JsonMapper
import tools.jackson.databind.module.SimpleModule
import tools.jackson.databind.ser.jdk.NumberSerializers
import tools.jackson.databind.{DeserializationFeature, ObjectMapper}
import tools.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule}

object JacksonSupport {

val mapper: ObjectMapper with ClassTagExtensions = new ObjectMapper with ClassTagExtensions
mapper.registerModule(DefaultScalaModule)

mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
val mapper: ObjectMapper with ClassTagExtensions = {
val jf = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES)
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.build()
JsonMapper.builder(jf)
.addModule(DefaultScalaModule)
.changeDefaultPropertyInclusion(_.withValueInclusion(JsonInclude.Include.NON_NULL))
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
.build() :: ClassTagExtensions
}

val module = new SimpleModule {
addSerializer(new NumberSerializers.DoubleSerializer(classOf[Double]))
Expand Down
Loading