Skip to content

Commit

Permalink
upgrade circe to 0.14.6 and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Dec 29, 2023
1 parent 2d3e583 commit 54dc863
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ lazy val library =
val pekkoHttp = "1.0.0"
val argonaut = "6.3.9"
val avro4s = "4.1.1"
val circe = "0.14.1"
val circe = "0.14.6"
val jacksonModuleScala = "2.16.1"
val json4s = "4.0.7"
val jsoniterScala = "2.26.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object ExampleApp {
}
} ~ pathPrefix("stream") {
post {
entity(as[SourceOf[Foo]]) { fooSource: SourceOf[Foo] =>
entity(as[SourceOf[Foo]]) { (fooSource: SourceOf[Foo]) =>
import sys._

Marshal(Source.single(Foo("a"))).to[RequestEntity]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ trait FailFastCirceSupport extends BaseCirceSupport with FailFastUnmarshaller
*/
object ErrorAccumulatingCirceSupport extends ErrorAccumulatingCirceSupport {
final case class DecodingFailures(failures: NonEmptyList[DecodingFailure]) extends Exception {
override def getMessage = failures.toList.map(_.show).mkString("\n")
override def getMessage: String = failures.toList.map(_.show).mkString("\n")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
import org.apache.pekko.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller }
import cats.data.{ NonEmptyList, ValidatedNel }
import cats.implicits.toShow
import io.circe.CursorOp.DownField
import io.circe.{ DecodingFailure, ParsingFailure, Printer }
import org.scalatest.concurrent.ScalaFutures
Expand Down Expand Up @@ -60,7 +61,7 @@ final class CirceSupportSpec
/**
* Specs common to both [[FailFastCirceSupport]] and [[ErrorAccumulatingCirceSupport]]
*/
private def commonCirceSupport(support: BaseCirceSupport) = {
private def commonCirceSupport(support: BaseCirceSupport): Unit = {
import io.circe.generic.auto._
import support._

Expand Down Expand Up @@ -131,21 +132,24 @@ final class CirceSupportSpec

"fail-fast and return only the first unmarshalling error" in {
val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""")
val error = DecodingFailure("String", List(DownField("a")))
val error =
DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a")))
Unmarshal(entity)
.to[MultiFoo]
.failed
.map(_ shouldBe error)
.map(_.getMessage shouldBe error.getMessage())
}

"fail-fast and return only the first unmarshalling error with safeUnmarshaller" in {
val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""")
val error = DecodingFailure("String", List(DownField("a")))
val error: io.circe.Error =
DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a")))
Unmarshal(entity)
.to[Either[io.circe.Error, MultiFoo]]
.futureValue
.left
.value shouldBe error
.value
.getMessage shouldBe error.getMessage
}

"allow unmarshalling with passed in Content-Types" in {
Expand Down Expand Up @@ -182,8 +186,8 @@ final class CirceSupportSpec
val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""")
val errors =
NonEmptyList.of(
DecodingFailure("String", List(DownField("a"))),
DecodingFailure("String", List(DownField("b")))
DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a"))),
DecodingFailure("Got value '2' with wrong type, expecting string", List(DownField("b")))
)
val errorMessage = ErrorAccumulatingCirceSupport.DecodingFailures(errors).getMessage
Unmarshal(entity)
Expand All @@ -194,18 +198,24 @@ final class CirceSupportSpec

"accumulate and return all unmarshalling errors with safeUnmarshaller" in {
val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""")
val errors =
val errors: NonEmptyList[DecodingFailure] =
NonEmptyList.of(
DecodingFailure("String", List(DownField("a"))),
DecodingFailure("String", List(DownField("b")))
DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a"))),
DecodingFailure("Got value '2' with wrong type, expecting string", List(DownField("b")))
)
val errorMessage = ErrorAccumulatingCirceSupport.DecodingFailures(errors).getMessage
Unmarshal(entity)
val result: String = Unmarshal(entity)
.to[ValidatedNel[io.circe.Error, MultiFoo]]
.futureValue
.toEither
.left
.value shouldBe errors
.value
.collect { case df: DecodingFailure =>
df.show
}
.mkString("\n")

errorMessage shouldBe result
}

"allow unmarshalling with passed in Content-Types" in {
Expand Down

0 comments on commit 54dc863

Please sign in to comment.