From 7a9e6135ef9bc808e50994878a9c6413974a823d Mon Sep 17 00:00:00 2001 From: Erlend Hamnaberg Date: Mon, 24 Jun 2024 15:17:57 +0200 Subject: [PATCH] run scalafixAll, and fix warnings --- .github/workflows/ci.yml | 4 -- .gitignore | 2 + .scalafix.conf | 3 ++ .../io/circe/jackson/JacksonCompat.scala | 11 ++++- .../io/circe/jackson/JacksonCompat.scala | 3 ++ .../io/circe/jackson/JacksonCompat.scala | 12 ++++- .../io/circe/jackson/JacksonCompat.scala | 11 ++++- .../circe/jackson/benchmark/Benchmark.scala | 12 ++++- .../benchmark/ParsingBenchmarkSpec.scala | 3 +- .../benchmark/PrintingBenchmarkSpec.scala | 4 +- build.sbt | 45 +++++-------------- project/plugins.sbt | 1 + .../circe/jackson/CirceJsonDeserializer.scala | 32 ++++++++----- .../io/circe/jackson/CirceJsonModule.scala | 14 +++--- .../circe/jackson/CirceJsonSerializer.scala | 13 ++++-- .../io/circe/jackson/JacksonParser.scala | 7 ++- .../io/circe/jackson/WithJacksonMapper.scala | 7 ++- .../main/scala/io/circe/jackson/package.scala | 25 ++++++----- .../scala/io/circe/jackson/CirceSuite.scala | 7 +-- .../io/circe/jackson/JacksonInstances.scala | 22 ++++++--- .../io/circe/jackson/JacksonParserSuite.scala | 9 ++-- .../circe/jackson/JacksonPrintingSuite.scala | 3 +- 22 files changed, 155 insertions(+), 95 deletions(-) create mode 100644 .scalafix.conf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6697c995..e3d444b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,10 +76,6 @@ jobs: if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest' run: sbt '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck - - name: Check scalafix lints - if: matrix.java == 'temurin@11' && matrix.os == 'ubuntu-latest' - run: sbt '++ ${{ matrix.scala }}' 'scalafixAll --check' - - name: Test run: sbt '++ ${{ matrix.scala }}' test diff --git a/.gitignore b/.gitignore index 495d8365..4c584c9d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ target/ .classpath tmp/ .bsp/ +.metals +.vscode diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 00000000..edf55aee --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,3 @@ +rules = [ + OrganizeImports +] diff --git a/210/src/main/scala/io/circe/jackson/JacksonCompat.scala b/210/src/main/scala/io/circe/jackson/JacksonCompat.scala index 060a0a54..ebf0e7bc 100644 --- a/210/src/main/scala/io/circe/jackson/JacksonCompat.scala +++ b/210/src/main/scala/io/circe/jackson/JacksonCompat.scala @@ -17,7 +17,10 @@ package io.circe.jackson import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.{ DeserializationContext, JsonNode, ObjectMapper, ObjectWriter } +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.ObjectWriter import com.fasterxml.jackson.databind.node.ObjectNode private[jackson] trait JacksonCompat { @@ -26,9 +29,13 @@ private[jackson] trait JacksonCompat { protected def handleUnexpectedToken(context: DeserializationContext)( klass: Class[_], parser: JsonParser - ): Unit = + ): Unit = { context.handleUnexpectedToken(klass, parser) + () + } protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll[JsonNode](fields) + + protected def currentName(jp: JsonParser): String = jp.currentName } diff --git a/25/src/main/scala/io/circe/jackson/JacksonCompat.scala b/25/src/main/scala/io/circe/jackson/JacksonCompat.scala index 198b93d7..0533f6e4 100644 --- a/25/src/main/scala/io/circe/jackson/JacksonCompat.scala +++ b/25/src/main/scala/io/circe/jackson/JacksonCompat.scala @@ -15,4 +15,7 @@ private[jackson] trait JacksonCompat { protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll(fields) + + protected def currentName(jp: JsonParser): String = jp.getCurrentName + } diff --git a/27/src/main/scala/io/circe/jackson/JacksonCompat.scala b/27/src/main/scala/io/circe/jackson/JacksonCompat.scala index 663ad825..61a3b56e 100644 --- a/27/src/main/scala/io/circe/jackson/JacksonCompat.scala +++ b/27/src/main/scala/io/circe/jackson/JacksonCompat.scala @@ -17,7 +17,10 @@ package io.circe.jackson import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.{ DeserializationContext, JsonNode, ObjectMapper, ObjectWriter } +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.ObjectWriter import com.fasterxml.jackson.databind.node.ObjectNode private[jackson] trait JacksonCompat { @@ -26,9 +29,14 @@ private[jackson] trait JacksonCompat { protected def handleUnexpectedToken(context: DeserializationContext)( klass: Class[_], parser: JsonParser - ): Unit = + ): Unit = { + val _ = parser throw context.mappingException(klass) + } protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll(fields) + + protected def currentName(jp: JsonParser): String = jp.getCurrentName + } diff --git a/28/src/main/scala/io/circe/jackson/JacksonCompat.scala b/28/src/main/scala/io/circe/jackson/JacksonCompat.scala index eb853673..8514f3ad 100644 --- a/28/src/main/scala/io/circe/jackson/JacksonCompat.scala +++ b/28/src/main/scala/io/circe/jackson/JacksonCompat.scala @@ -17,7 +17,10 @@ package io.circe.jackson import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.{ DeserializationContext, JsonNode, ObjectMapper, ObjectWriter } +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.ObjectWriter import com.fasterxml.jackson.databind.node.ObjectNode private[jackson] trait JacksonCompat { @@ -26,9 +29,13 @@ private[jackson] trait JacksonCompat { protected def handleUnexpectedToken(context: DeserializationContext)( klass: Class[_], parser: JsonParser - ): Unit = + ): Unit = { context.handleUnexpectedToken(klass, parser) + () + } protected def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode = node.setAll(fields) + + protected def currentName(jp: JsonParser): String = jp.getCurrentName } diff --git a/benchmark/src/main/scala/io/circe/jackson/benchmark/Benchmark.scala b/benchmark/src/main/scala/io/circe/jackson/benchmark/Benchmark.scala index 22ed0d03..2e367140 100644 --- a/benchmark/src/main/scala/io/circe/jackson/benchmark/Benchmark.scala +++ b/benchmark/src/main/scala/io/circe/jackson/benchmark/Benchmark.scala @@ -17,12 +17,16 @@ package io.circe.jackson.benchmark import cats.Eq -import io.circe.{ Decoder, Encoder, Json => JsonC } +import io.circe.Decoder +import io.circe.Encoder import io.circe.generic.semiauto._ import io.circe.jawn._ +import io.circe.{ Json => JsonC } +import org.openjdk.jmh.annotations._ + import java.nio.ByteBuffer import java.util.concurrent.TimeUnit -import org.openjdk.jmh.annotations._ +import scala.annotation.nowarn case class Foo(s: String, d: Double, i: Int, l: Long, bs: List[Boolean]) @@ -62,15 +66,19 @@ class ExampleData { @OutputTimeUnit(TimeUnit.SECONDS) class ParsingBenchmark extends ExampleData { @Benchmark + @nowarn("cat=deprecation") def parseIntsC: JsonC = parse(intsJson).right.getOrElse(throw new Exception) @Benchmark + @nowarn("cat=deprecation") def parseIntsCJ: JsonC = io.circe.jackson.parse(intsJson).right.getOrElse(throw new Exception) @Benchmark + @nowarn("cat=deprecation") def parseFoosC: JsonC = parse(foosJson).right.getOrElse(throw new Exception) @Benchmark + @nowarn("cat=deprecation") def parseFoosCJ: JsonC = io.circe.jackson.parse(foosJson).right.getOrElse(throw new Exception) } diff --git a/benchmark/src/test/scala/io/circe/jackson/benchmark/ParsingBenchmarkSpec.scala b/benchmark/src/test/scala/io/circe/jackson/benchmark/ParsingBenchmarkSpec.scala index 66bce74c..a7d1b3b9 100644 --- a/benchmark/src/test/scala/io/circe/jackson/benchmark/ParsingBenchmarkSpec.scala +++ b/benchmark/src/test/scala/io/circe/jackson/benchmark/ParsingBenchmarkSpec.scala @@ -17,8 +17,9 @@ package io.circe.jackson.benchmark import cats.instances.AllInstances -import io.circe.testing.{ ArbitraryInstances, EqInstances } import cats.syntax.AllSyntax +import io.circe.testing.ArbitraryInstances +import io.circe.testing.EqInstances class ParsingBenchmarkSpec extends munit.FunSuite diff --git a/benchmark/src/test/scala/io/circe/jackson/benchmark/PrintingBenchmarkSpec.scala b/benchmark/src/test/scala/io/circe/jackson/benchmark/PrintingBenchmarkSpec.scala index 266b4449..66d4bc07 100644 --- a/benchmark/src/test/scala/io/circe/jackson/benchmark/PrintingBenchmarkSpec.scala +++ b/benchmark/src/test/scala/io/circe/jackson/benchmark/PrintingBenchmarkSpec.scala @@ -17,9 +17,11 @@ package io.circe.jackson.benchmark import cats.instances.AllInstances -import io.circe.testing.{ ArbitraryInstances, EqInstances } import cats.syntax.AllSyntax import io.circe.parser.decode +import io.circe.testing.ArbitraryInstances +import io.circe.testing.EqInstances + import java.nio.ByteBuffer class PrintingBenchmarkSpec diff --git a/build.sbt b/build.sbt index 60401da8..abf6c395 100644 --- a/build.sbt +++ b/build.sbt @@ -3,19 +3,11 @@ ThisBuild / crossScalaVersions := Seq("2.13.14", "2.12.19", "3.3.3") ThisBuild / scalaVersion := crossScalaVersions.value.head ThisBuild / githubWorkflowPublishTargetBranches := Nil ThisBuild / startYear := Some(2016) -ThisBuild / tlBaseVersion := "0.14" - -val compilerOptions = Seq( - "-deprecation", - "-encoding", - "UTF-8", - "-feature", - "-language:existentials", - "-language:higherKinds", - "-unchecked", - "-Ywarn-dead-code", - "-Ywarn-numeric-widen" -) +ThisBuild / tlBaseVersion := "0.15" +ThisBuild / scalafixAll / skip := tlIsScala3.value +ThisBuild / ScalafixConfig / skip := tlIsScala3.value +ThisBuild / tlCiScalafixCheck := false // TODO: Address these in a follow up PR +ThisBuild / tlFatalWarnings := false // TODO: fix by dropping 2.12 val circeVersion = "0.14.8" val munitVersion = "1.0.0" @@ -29,34 +21,18 @@ def priorTo2_13(scalaVersion: String): Boolean = } val baseSettings = Seq( - scalacOptions ++= compilerOptions, - scalacOptions ++= ( - if (priorTo2_13(scalaVersion.value)) - Seq( - "-Xfuture", - "-Yno-adapted-args", - "-Ywarn-unused-import" - ) - else - Seq( - "-Ywarn-unused:imports" - ) - ), - Compile / console / scalacOptions ~= { - _.filterNot(Set("-Ywarn-unused-import")) - }, - Test / console / scalacOptions ~= { - _.filterNot(Set("-Ywarn-unused-import")) - }, resolvers ++= Resolver.sonatypeOssRepos("releases"), resolvers ++= Resolver.sonatypeOssRepos("snapshots"), coverageHighlighting := true, - coverageEnabled := (if (scalaVersion.value.startsWith("3")) false else coverageEnabled.value), + coverageEnabled := !tlIsScala3.value, libraryDependencies ++= Seq( "io.circe" %% "circe-core" % circeVersion, + "org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0", "io.circe" %% "circe-jawn" % circeVersion % Test, "io.circe" %% "circe-testing" % circeVersion % Test, - "org.typelevel" %% "discipline-munit" % disciplineMunitVersion % Test + "org.typelevel" %% "discipline-munit" % disciplineMunitVersion % Test, + "org.scalameta" %% "munit" % munitVersion % Test, + "org.scalameta" %% "munit-scalacheck" % munitVersion % Test ), Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "shared/src/main", Test / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "shared/src/test", @@ -137,7 +113,6 @@ lazy val jackson28 = project "-sourcepath", (LocalRootProject / baseDirectory).value.getAbsolutePath ), - git.remoteRepo := "git@github.com:circe/circe-jackson.git", autoAPIMappings := true, apiURL := Some(url("https://circe.github.io/circe-jackson/api/")), mimaPreviousArtifacts := Set("io.circe" %% "circe-jackson28" % previousCirceJacksonVersion) diff --git a/project/plugins.sbt b/project/plugins.sbt index 5e1d489d..6a3ecf9e 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,4 @@ addSbtPlugin("io.circe" % "sbt-circe-org" % "0.4.1") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.6") +addSbtPlugin("com.timushev.sbt" % "sbt-rewarn" % "0.1.3") diff --git a/shared/src/main/scala/io/circe/jackson/CirceJsonDeserializer.scala b/shared/src/main/scala/io/circe/jackson/CirceJsonDeserializer.scala index 06a82c77..15259850 100644 --- a/shared/src/main/scala/io/circe/jackson/CirceJsonDeserializer.scala +++ b/shared/src/main/scala/io/circe/jackson/CirceJsonDeserializer.scala @@ -16,13 +16,19 @@ package io.circe.jackson -import com.fasterxml.jackson.core.{ JsonParser, JsonTokenId } -import com.fasterxml.jackson.databind.{ DeserializationContext, JsonDeserializer } +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.core.JsonTokenId +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonDeserializer import com.fasterxml.jackson.databind.`type`.TypeFactory -import io.circe.{ Json, JsonBigDecimal } +import io.circe.Json +import io.circe.JsonBigDecimal + import java.util.ArrayList -import scala.annotation.{ switch, tailrec } -import scala.collection.JavaConverters._ +import scala.annotation.nowarn +import scala.annotation.switch +import scala.annotation.tailrec +import scala.jdk.CollectionConverters._ private[jackson] sealed trait DeserializerContext { def addValue(value: Json): DeserializerContext @@ -46,7 +52,7 @@ private[jackson] final case class ReadingMap(content: ArrayList[(String, Json)]) throw new Exception("Cannot add a value on an object without a key, malformed JSON object!") } -private[jackson] final class CirceJsonDeserializer(factory: TypeFactory, klass: Class[_]) +private[jackson] final class CirceJsonDeserializer(@nowarn factory: TypeFactory, klass: Class[_]) extends JsonDeserializer[Object] with JacksonCompat { override final def isCachable: Boolean = true @@ -64,7 +70,10 @@ private[jackson] final class CirceJsonDeserializer(factory: TypeFactory, klass: ctxt: DeserializationContext, parserContext: List[DeserializerContext] ): Json = { - if (jp.getCurrentToken == null) jp.nextToken() + if (jp.getCurrentToken == null) { + jp.nextToken() + () + } val (maybeValue, nextContext) = (jp.getCurrentToken.id(): @switch) match { case JsonTokenId.ID_NUMBER_INT | JsonTokenId.ID_NUMBER_FLOAT => @@ -87,7 +96,7 @@ private[jackson] final class CirceJsonDeserializer(factory: TypeFactory, klass: case JsonTokenId.ID_FIELD_NAME => parserContext match { - case (c: ReadingMap) :: stack => (None, c.setField(jp.getCurrentName) +: stack) + case (c: ReadingMap) :: stack => (None, c.setField(currentName(jp)) +: stack) case _ => throw new RuntimeException("We weren't reading an object, something went wrong") } @@ -113,8 +122,11 @@ private[jackson] final class CirceJsonDeserializer(factory: TypeFactory, klass: case maybeValue => jp.nextToken() val toPass = maybeValue.map { v => - val previous :: stack = nextContext - (previous.addValue(v)) +: stack + nextContext match { + case previous :: stack => + (previous.addValue(v)) +: stack + case Nil => nextContext + } }.getOrElse(nextContext) deserialize(jp, ctxt, toPass) diff --git a/shared/src/main/scala/io/circe/jackson/CirceJsonModule.scala b/shared/src/main/scala/io/circe/jackson/CirceJsonModule.scala index 4b79cc23..0c32d4c4 100644 --- a/shared/src/main/scala/io/circe/jackson/CirceJsonModule.scala +++ b/shared/src/main/scala/io/circe/jackson/CirceJsonModule.scala @@ -17,20 +17,18 @@ package io.circe.jackson import com.fasterxml.jackson.core.Version -import com.fasterxml.jackson.databind.{ - BeanDescription, - DeserializationConfig, - JavaType, - JsonSerializer, - SerializationConfig -} +import com.fasterxml.jackson.databind.BeanDescription +import com.fasterxml.jackson.databind.DeserializationConfig +import com.fasterxml.jackson.databind.JavaType +import com.fasterxml.jackson.databind.JsonSerializer import com.fasterxml.jackson.databind.Module.SetupContext +import com.fasterxml.jackson.databind.SerializationConfig import com.fasterxml.jackson.databind.deser.Deserializers import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.ser.Serializers import io.circe.Json -final object CirceJsonModule extends SimpleModule("CirceJson", Version.unknownVersion()) { +object CirceJsonModule extends SimpleModule("CirceJson", Version.unknownVersion()) { override final def setupModule(context: SetupContext): Unit = { context.addDeserializers( new Deserializers.Base { diff --git a/shared/src/main/scala/io/circe/jackson/CirceJsonSerializer.scala b/shared/src/main/scala/io/circe/jackson/CirceJsonSerializer.scala index ffad6b67..5184b578 100644 --- a/shared/src/main/scala/io/circe/jackson/CirceJsonSerializer.scala +++ b/shared/src/main/scala/io/circe/jackson/CirceJsonSerializer.scala @@ -17,10 +17,17 @@ package io.circe.jackson import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.databind.{ JsonSerializer, SerializerProvider } -import io.circe.{ Json, JsonBigDecimal, JsonBiggerDecimal, JsonDecimal, JsonDouble, JsonFloat, JsonLong } +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.SerializerProvider +import io.circe.Json +import io.circe.JsonBigDecimal +import io.circe.JsonBiggerDecimal +import io.circe.JsonDecimal +import io.circe.JsonDouble +import io.circe.JsonFloat +import io.circe.JsonLong -private[jackson] final object CirceJsonSerializer extends JsonSerializer[Json] { +private[jackson] object CirceJsonSerializer extends JsonSerializer[Json] { import java.math.{ BigDecimal => JBigDecimal, BigInteger } import com.fasterxml.jackson.databind.node.{ BigIntegerNode, DecimalNode } diff --git a/shared/src/main/scala/io/circe/jackson/JacksonParser.scala b/shared/src/main/scala/io/circe/jackson/JacksonParser.scala index 4bf4559a..06d55172 100644 --- a/shared/src/main/scala/io/circe/jackson/JacksonParser.scala +++ b/shared/src/main/scala/io/circe/jackson/JacksonParser.scala @@ -17,7 +17,12 @@ package io.circe.jackson import cats.data.ValidatedNel -import io.circe.{ Decoder, Error, Json, Parser, ParsingFailure } +import io.circe.Decoder +import io.circe.Error +import io.circe.Json +import io.circe.Parser +import io.circe.ParsingFailure + import java.io.File import scala.util.control.NonFatal diff --git a/shared/src/main/scala/io/circe/jackson/WithJacksonMapper.scala b/shared/src/main/scala/io/circe/jackson/WithJacksonMapper.scala index a5ddcd52..29e0eb99 100644 --- a/shared/src/main/scala/io/circe/jackson/WithJacksonMapper.scala +++ b/shared/src/main/scala/io/circe/jackson/WithJacksonMapper.scala @@ -16,9 +16,12 @@ package io.circe.jackson -import com.fasterxml.jackson.core.{ JsonFactory, JsonParser } +import com.fasterxml.jackson.core.JsonFactory +import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.ObjectMapper -import java.io.{ File, Writer } + +import java.io.File +import java.io.Writer class WithJacksonMapper { final val mapper: ObjectMapper = (new ObjectMapper).registerModule(CirceJsonModule) diff --git a/shared/src/main/scala/io/circe/jackson/package.scala b/shared/src/main/scala/io/circe/jackson/package.scala index 4efa34af..174944a4 100644 --- a/shared/src/main/scala/io/circe/jackson/package.scala +++ b/shared/src/main/scala/io/circe/jackson/package.scala @@ -18,10 +18,12 @@ package io.circe import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node._ + import java.io._ import java.math.{ BigDecimal => JBigDecimal } import java.nio.ByteBuffer -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ +import scala.collection.compat._ /** * Support for Jackson-powered parsing and printing for circe. @@ -48,10 +50,6 @@ package object jackson extends WithJacksonMapper with JacksonParser with Jackson sw.toString } - private[this] class EnhancedByteArrayOutputStream extends ByteArrayOutputStream { - def toByteBuffer: ByteBuffer = ByteBuffer.wrap(this.buf, 0, this.size) - } - final def jacksonPrintByteBuffer(json: Json): ByteBuffer = { val bytes = new EnhancedByteArrayOutputStream writeJson(new BufferedWriter(new OutputStreamWriter(bytes, "UTF-8")), json) @@ -86,12 +84,13 @@ package object jackson extends WithJacksonMapper with JacksonParser with Jackson try { DecimalNode.valueOf(new JBigDecimal(x)) } catch { - case nfe: NumberFormatException => TextNode.valueOf(x) + case _: NumberFormatException => TextNode.valueOf(x) } }, TextNode.valueOf(_), - array => JsonNodeFactory.instance.arrayNode.addAll(array.map(circeToJackson).asJava), - obj => objectNodeSetAll(JsonNodeFactory.instance.objectNode, obj.toMap.mapValues(circeToJackson).toMap.asJava) + array => JsonNodeFactory.instance.arrayNode.addAll(array.map(circeToJackson(_)).asJava), + obj => + objectNodeSetAll(JsonNodeFactory.instance.objectNode, obj.toMap.view.mapValues(circeToJackson(_)).toMap.asJava) ) /** @@ -111,10 +110,16 @@ package object jackson extends WithJacksonMapper with JacksonParser with Jackson Json.fromBigInt(node.bigIntegerValue) } case JsonNodeType.ARRAY => - Json.fromValues(node.elements.asScala.map(jacksonToCirce).toIterable) + Json.fromValues(node.elements.asScala.map(jacksonToCirce(_)).to(Iterable)) case JsonNodeType.OBJECT => - Json.fromFields(node.fields.asScala.map(m => (m.getKey, jacksonToCirce(m.getValue))).toIterable) + Json.fromFields(node.fields.asScala.map(m => (m.getKey, jacksonToCirce(m.getValue))).to(Iterable)) case _ => Json.Null } } + +package jackson { + private[jackson] class EnhancedByteArrayOutputStream extends ByteArrayOutputStream { + def toByteBuffer: ByteBuffer = ByteBuffer.wrap(this.buf, 0, this.size) + } +} diff --git a/shared/src/test/scala/io/circe/jackson/CirceSuite.scala b/shared/src/test/scala/io/circe/jackson/CirceSuite.scala index 23be3ca6..817db95a 100644 --- a/shared/src/test/scala/io/circe/jackson/CirceSuite.scala +++ b/shared/src/test/scala/io/circe/jackson/CirceSuite.scala @@ -17,11 +17,12 @@ package io.circe.jackson import cats.instances.AllInstances -import cats.syntax.{ AllSyntax, EitherOps } +import cats.syntax.AllSyntax +import cats.syntax.EitherOps import io.circe.Json -import io.circe.testing.{ ArbitraryInstances, EqInstances } +import io.circe.testing.ArbitraryInstances +import io.circe.testing.EqInstances import munit.ScalaCheckSuite -import scala.language.implicitConversions /** * An opinionated stack of traits to improve consistency and reduce boilerplate in circe tests. diff --git a/shared/src/test/scala/io/circe/jackson/JacksonInstances.scala b/shared/src/test/scala/io/circe/jackson/JacksonInstances.scala index 725356f7..07c88439 100644 --- a/shared/src/test/scala/io/circe/jackson/JacksonInstances.scala +++ b/shared/src/test/scala/io/circe/jackson/JacksonInstances.scala @@ -19,14 +19,26 @@ package io.circe.jackson import cats.Eq import cats.instances.list._ import cats.instances.map._ -import io.circe.{ Json, JsonBigDecimal, JsonBiggerDecimal, JsonDecimal, JsonDouble, JsonFloat, JsonLong, JsonNumber } -import io.circe.Json.{ JArray, JNumber, JObject, JString } +import io.circe.Json +import io.circe.Json.JArray +import io.circe.Json.JNumber +import io.circe.Json.JObject +import io.circe.Json.JString +import io.circe.JsonBigDecimal +import io.circe.JsonBiggerDecimal +import io.circe.JsonDecimal +import io.circe.JsonDouble +import io.circe.JsonFloat +import io.circe.JsonLong +import io.circe.JsonNumber import io.circe.numbers.BiggerDecimal -import io.circe.testing.ArbitraryInstances import org.scalacheck.Arbitrary -import scala.util.matching.Regex -import scala.util.Try + import java.nio.ByteBuffer +import scala.util.Try + +import io.circe.testing.ArbitraryInstances +import scala.util.matching.Regex trait JacksonInstances { this: ArbitraryInstances => diff --git a/shared/src/test/scala/io/circe/jackson/JacksonParserSuite.scala b/shared/src/test/scala/io/circe/jackson/JacksonParserSuite.scala index 20bb1733..ddc3cb4b 100644 --- a/shared/src/test/scala/io/circe/jackson/JacksonParserSuite.scala +++ b/shared/src/test/scala/io/circe/jackson/JacksonParserSuite.scala @@ -18,13 +18,16 @@ package io.circe.jackson import cats.data.Validated import com.fasterxml.jackson.core.JsonToken -import com.fasterxml.jackson.databind.{ ObjectMapper, ObjectReader } +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.ObjectReader import io.circe.Json import io.circe.testing.ParserTests -import java.io.{ ByteArrayInputStream, File } +import munit.DisciplineSuite import org.scalacheck.Prop + +import java.io.ByteArrayInputStream +import java.io.File import scala.io.Source -import munit.DisciplineSuite class JacksonParserSuite extends CirceSuite with DisciplineSuite with JacksonInstances { diff --git a/shared/src/test/scala/io/circe/jackson/JacksonPrintingSuite.scala b/shared/src/test/scala/io/circe/jackson/JacksonPrintingSuite.scala index 29c75604..f93379bc 100644 --- a/shared/src/test/scala/io/circe/jackson/JacksonPrintingSuite.scala +++ b/shared/src/test/scala/io/circe/jackson/JacksonPrintingSuite.scala @@ -17,9 +17,10 @@ package io.circe.jackson import io.circe.Json -import java.nio.ByteBuffer import org.scalacheck.Prop.forAll +import java.nio.ByteBuffer + class JacksonPrintingSuite extends CirceSuite with JacksonInstances { property("jacksonPrint should produce round-trippable output") { forAll { (json: Json) =>