Skip to content

Commit

Permalink
run scalafixAll, and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hamnis committed Jun 24, 2024
1 parent 3b75457 commit 7a9e613
Show file tree
Hide file tree
Showing 22 changed files with 155 additions and 95 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ target/
.classpath
tmp/
.bsp/
.metals
.vscode
3 changes: 3 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rules = [
OrganizeImports
]
11 changes: 9 additions & 2 deletions 210/src/main/scala/io/circe/jackson/JacksonCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions 25/src/main/scala/io/circe/jackson/JacksonCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
12 changes: 10 additions & 2 deletions 27/src/main/scala/io/circe/jackson/JacksonCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

}
11 changes: 9 additions & 2 deletions 28/src/main/scala/io/circe/jackson/JacksonCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 10 additions & 35 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -137,7 +113,6 @@ lazy val jackson28 = project
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath
),
git.remoteRepo := "[email protected]:circe/circe-jackson.git",
autoAPIMappings := true,
apiURL := Some(url("https://circe.github.io/circe-jackson/api/")),
mimaPreviousArtifacts := Set("io.circe" %% "circe-jackson28" % previousCirceJacksonVersion)
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
32 changes: 22 additions & 10 deletions shared/src/main/scala/io/circe/jackson/CirceJsonDeserializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 =>
Expand All @@ -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")
}

Expand All @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions shared/src/main/scala/io/circe/jackson/CirceJsonModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions shared/src/main/scala/io/circe/jackson/CirceJsonSerializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
7 changes: 6 additions & 1 deletion shared/src/main/scala/io/circe/jackson/JacksonParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 7a9e613

Please sign in to comment.