Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hamnis committed Jun 24, 2024
1 parent 1e07399 commit 80944e5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
6 changes: 5 additions & 1 deletion 210/src/main/scala/io/circe/jackson/JacksonCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,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

}
3 changes: 3 additions & 0 deletions 27/src/main/scala/io/circe/jackson/JacksonCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,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

}
6 changes: 5 additions & 1 deletion 28/src/main/scala/io/circe/jackson/JacksonCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,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
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ val baseSettings = Seq(
coverageEnabled := (if (scalaVersion.value.startsWith("3")) false else coverageEnabled.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,
Expand Down Expand Up @@ -109,7 +110,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
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import io.circe.Json
import io.circe.JsonBigDecimal

import java.util.ArrayList
import scala.annotation.nowarn
import scala.annotation.switch
import scala.annotation.tailrec
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

private[jackson] sealed trait DeserializerContext {
def addValue(value: Json): DeserializerContext
Expand All @@ -51,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 Down Expand Up @@ -92,7 +93,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 @@ -118,8 +119,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: 8 additions & 6 deletions shared/src/main/scala/io/circe/jackson/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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._

/**
* Support for Jackson-powered parsing and printing for circe.
Expand All @@ -49,10 +49,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)
Expand Down Expand Up @@ -87,7 +83,7 @@ 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(_),
Expand Down Expand Up @@ -119,3 +115,9 @@ package object jackson extends WithJacksonMapper with JacksonParser with Jackson
}

}

package jackson {
private[jackson] class EnhancedByteArrayOutputStream extends ByteArrayOutputStream {
def toByteBuffer: ByteBuffer = ByteBuffer.wrap(this.buf, 0, this.size)
}
}

0 comments on commit 80944e5

Please sign in to comment.