Permalink
Browse files

Upgrade circe to 0.9.1 (#25)

  • Loading branch information...
darkjh authored and alexarchambault committed Jun 14, 2018
1 parent f18c905 commit ff47f49d580810a096770fa03f7c2a62e0e23298
@@ -6,7 +6,7 @@ import io.circe.{ ACursor, Decoder, HCursor, Json }
abstract class JsonProductCodec {
def encodeEmpty: Json
def encodeField(field: (String, Json), obj: Json, default: => Option[Json]): Json
def decodeEmpty(cursor: HCursor): Decoder.Result[Unit]
def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A], default: Option[A]): Decoder.Result[(A, ACursor)]
}
@@ -48,15 +48,15 @@ class JsonProductObjCodec extends JsonProductCodec {
def decodeEmpty(cursor: HCursor): Decoder.Result[Unit] = Right(())
def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A], default: Option[A]): Decoder.Result[(A, ACursor)] = {
val c = cursor.downField(toJsonName(name))
def result = c.as(decode).right.map((_, ACursor.ok(cursor)))
def result = c.as(decode).right.map((_, cursor))
default match {
case None => result
case Some(d) =>
if (c.succeeded)
result
else
Right((d, ACursor.ok(cursor)))
Right((d, cursor))
}
}
}
@@ -49,10 +49,10 @@ class JsonSumObjCodec extends JsonSumCodec {
cursor.history
))
def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A]): Decoder.Result[Either[ACursor, A]] =
cursor.downField(toJsonName(name)).either match {
case Left(_) =>
Right(Left(ACursor.ok(cursor)))
case Right(content) =>
cursor.downField(toJsonName(name)).success match {
case None =>
Right(Left(cursor))
case Some(content) =>
decode(content).right.map(Right(_))
}
}
@@ -87,7 +87,7 @@ class JsonSumTypeFieldCodec extends JsonSumCodec {
case Right(name0) if toTypeValue(name) == name0 =>
c.delete.as(decode).right.map(Right(_))
case _ =>
Right(Left(ACursor.ok(cursor)))
Right(Left(cursor))
}
}
}
@@ -103,7 +103,7 @@ object ProductEncodeTests extends TestSuite {
Default.AsOptions[WrappedMap],
HListProductEncoder.hcons(
Witness('m),
Encoder.encodeMapLike[Map, String, Json](KeyEncoder.encodeKeyString, Encoder.encodeJson),
Encoder.encodeMapLike[String, Json, Map](KeyEncoder.encodeKeyString, Encoder.encodeJson, identity),
HListProductEncoder.hnil
)
),
View
@@ -8,7 +8,7 @@ object Deps {
import Def.setting
private val jupyterScalaVersion = "0.4.0"
private val circeVersion = "0.6.1"
private val circeVersion = "0.9.1"
def circeCore = setting("io.circe" %%% "circe-core" % circeVersion)
@@ -13,7 +13,7 @@ import java.lang.{Boolean => JBoolean, Double => JDouble, Integer => JInt}
object Plotly {
private val printer = Printer.noSpaces.copy(dropNullKeys = true)
private val printer = Printer.noSpaces.copy(dropNullValues = true)
private def stripNulls(json: Json): js.Any = {
// Remove empty objects
JSON.parse(printer.pretty(json))
@@ -16,7 +16,7 @@ import scala.annotation.tailrec
object Plotly {
private val printer = Printer.noSpaces.copy(dropNullKeys = true)
private val printer = Printer.noSpaces.copy(dropNullValues = true)
def jsSnippet(div: String, data: Seq[Trace], layout: Layout): String = {
@@ -182,7 +182,7 @@ object Plotly {
openInBrowser = openInBrowser,
addSuffixIfExists = addSuffixIfExists
)
def plot(
path: String = "./plot.html",
title: String = null,
@@ -267,7 +267,7 @@ object Plotly {
openInBrowser = openInBrowser,
addSuffixIfExists = addSuffixIfExists
)
def plot(
path: String = "./plot.html",
title: String = null,
@@ -160,7 +160,7 @@ object Codecs {
Right {
val o = decode(cursor)
o.right.toOption
.toRight(ACursor.ok(cursor))
.toRight(cursor)
}
}
@@ -176,7 +176,7 @@ object Codecs {
underlying.encodeField(field, obj, default)
def decodeEmpty(cursor: HCursor): Decoder.Result[Unit] =
if (cursor.focus == Json.obj())
if (cursor.focus.contains(Json.obj()))
Right(())
else
Left(DecodingFailure(
@@ -187,15 +187,15 @@ object Codecs {
def decodeField[A](name: String, cursor: HCursor, decode: Decoder[A], default: Option[A]): Decoder.Result[(A, ACursor)] = {
val c = cursor.downField(toJsonName(name))
def result = c.as(decode).right.map((_, if (c.succeeded) c.delete else cursor.acursor))
def result = c.as(decode).right.map((_, if (c.succeeded) c.delete else cursor))
default match {
case None => result
case Some(d) =>
if (c.succeeded)
result
else
Right((d, ACursor.ok(cursor)))
Right((d, cursor))
}
}
}
@@ -404,12 +404,12 @@ object Codecs {
implicit val decodeError: Decoder[Error] =
Decoder.instance { c =>
c.downField("type").either match {
case Left(c0) =>
Left(DecodingFailure("No type found", c0.history))
case Right(c1) =>
c.downField("type").success match {
case None =>
Left(DecodingFailure("No type found", c.history))
case Some(c1) =>
val c0 = c1.delete
c1.focus.as[String].right.flatMap {
c1.focus.get.as[String].right.flatMap {
case "data" =>
c0.as[Error.Data].right.map(e => e: Error)
case "percent" =>
@@ -449,7 +449,7 @@ object Codecs {
case Left(_) if name == "Scatter" => // assume scatter if no type found
cursor.as(decode).right.map(Right(_))
case _ =>
Right(Left(ACursor.ok(cursor)))
Right(Left(cursor))
}
}
}
@@ -42,7 +42,7 @@ object SchemaTests {
val constantString = c.as[String].right.map[Attribute](ConstantString(_))
def flag = c.as[Flag].right.map[Attribute](x => x)
def enumerated = c.as[Enumerated].right.map[Attribute](x => x)
def other = Right(Other(c.focus))
def other = Right(Other(c.focus.get))
constantString.right.toOption.map(Right(_))
.orElse(flag.right.toOption.map(Right(_)))

0 comments on commit ff47f49

Please sign in to comment.