Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Build settings
// *****************************************************************************

lazy val scalaReleaseVersion = SettingKey[Int]("scalaReleaseVersion")
inThisBuild(
Seq(
organization := "com.github.pjfanning",
Expand Down Expand Up @@ -41,7 +42,13 @@ inThisBuild(
),
resolvers += "Apache Snapshots" at "https://repository.apache.org/content/groups/snapshots",
scalafmtOnCompile := true,
dynverSeparator := "_" // the default `+` is not compatible with docker tags,
dynverSeparator := "_", // the default `+` is not compatible with docker tags
scalaReleaseVersion := {
lazy val v = scalaVersion.value
CrossVersion.partialVersion(v).map(_._1.toInt).getOrElse {
throw new RuntimeException(s"could not get Scala release version from $v")
}
}
)
)

Expand Down Expand Up @@ -90,7 +97,7 @@ lazy val `pekko-http-argonaut` =

lazy val `pekko-http-circe` =
project
.settings(commonSettings)
.settings(commonSettings, withScala3)
.settings(
libraryDependencies ++= Seq(
library.pekkoHttp,
Expand All @@ -99,7 +106,18 @@ lazy val `pekko-http-circe` =
library.pekkoStream % Provided,
library.circeGeneric % Test,
library.scalaTest % Test,
)
),
Test / unmanagedSourceDirectories ++= {
if (scalaReleaseVersion.value > 2) {
Seq(
(LocalRootProject / baseDirectory).value / "src" / "test" / "scala-3"
)
} else {
Seq(
(LocalRootProject / baseDirectory).value / "src" / "test" / "scala-2",
)
}
}
)

lazy val `pekko-http-jackson` =
Expand Down Expand Up @@ -168,7 +186,7 @@ lazy val `pekko-http-play-json` =

lazy val `pekko-http-upickle` =
project
.settings(commonSettings)
.settings(commonSettings, withScala3)
.settings(
libraryDependencies ++= Seq(
library.pekkoHttp,
Expand Down Expand Up @@ -232,8 +250,8 @@ lazy val library =
val jsoniterScala = "2.17.9"
val ninny = "0.7.0"
val play = "2.9.2"
val scalaTest = "3.2.11"
val upickle = "1.5.0"
val scalaTest = "3.2.15"
val upickle = "1.6.0"
val zioJson = "0.3.0"
}
// format: off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object ExampleApp {
final case class Foo(bar: String)

def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val system: ActorSystem = ActorSystem()

Http().newServerAt("127.0.0.1", 8000).bindFlow(route)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2015 Heiko Seeberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.pjfanning.pekkohttpcirce

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.marshalling.Marshal
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import org.apache.pekko.stream.scaladsl.{ Sink, Source }
import io.circe.Encoder
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
import org.scalatest.{ BeforeAndAfterAll, EitherValues }

import scala.concurrent.Await
import scala.concurrent.duration.DurationInt

final class CirceSupportSpec2
extends AsyncWordSpec
with Matchers
with BeforeAndAfterAll
with ScalaFutures
with EitherValues {

import CirceSupportSpec._

private implicit val system: ActorSystem = ActorSystem()

/**
* Specs common to both [[FailFastCirceSupport]] and [[ErrorAccumulatingCirceSupport]]
*/
private def commonCirceSupport(support: BaseCirceSupport) = {
import io.circe.generic.auto._
import support._

"enable streamed marshalling and unmarshalling for json arrays" in {
val foos = (0 to 100).map(i => Foo(s"bar-$i")).toList

// Don't know why, the encoder is not resolving alongside the marshaller
// this only happens if we use the implicits from BaseCirceSupport
// so, tried to create it before and guess what? it worked.
// not sure if this is a bug, but, the error is this:
// diverging implicit expansion for type io.circe.Encoder[A]
// [error] starting with lazy value encodeZoneOffset in object Encoder
implicit val e = implicitly[Encoder[Foo]]

Marshal(Source(foos))
.to[ResponseEntity]
.flatMap(entity => Unmarshal(entity).to[SourceOf[Foo]])
.flatMap(_.runWith(Sink.seq))
.map(_ shouldBe foos)
}

}

"FailFastCirceSupport" should {
behave like commonCirceSupport(FailFastCirceSupport)
}

"ErrorAccumulatingCirceSupport" should {
behave like commonCirceSupport(ErrorAccumulatingCirceSupport)

}

override protected def afterAll(): Unit = {
Await.ready(system.terminate(), 42.seconds)
super.afterAll()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2015 Heiko Seeberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.pjfanning.pekkohttpcirce

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.marshalling.Marshal
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import org.apache.pekko.stream.scaladsl.{ Sink, Source }
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
import org.scalatest.{ BeforeAndAfterAll, EitherValues }

import scala.concurrent.Await
import scala.concurrent.duration.DurationInt

final class CirceSupportSpec2
extends AsyncWordSpec
with Matchers
with BeforeAndAfterAll
with ScalaFutures
with EitherValues {

import CirceSupportSpec._

private implicit val system: ActorSystem = ActorSystem()

/**
* Specs common to both [[FailFastCirceSupport]] and [[ErrorAccumulatingCirceSupport]]
*/
private def commonCirceSupport(support: BaseCirceSupport) = {
import io.circe.generic.auto._
import support._

"enable streamed marshalling and unmarshalling for json arrays" in {
val foos = (0 to 100).map(i => Foo(s"bar-$i")).toList

Marshal(Source(foos))
.to[ResponseEntity]
.flatMap(entity => Unmarshal(entity).to[SourceOf[Foo]])
.flatMap(_.runWith(Sink.seq))
.map(_ shouldBe foos)
}

}

"FailFastCirceSupport" should {
behave like commonCirceSupport(FailFastCirceSupport)
}

"ErrorAccumulatingCirceSupport" should {
behave like commonCirceSupport(ErrorAccumulatingCirceSupport)

}

override protected def afterAll(): Unit = {
Await.ready(system.terminate(), 42.seconds)
super.afterAll()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,18 @@ package com.github.pjfanning.pekkohttpcirce

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.marshalling.Marshal
import org.apache.pekko.http.scaladsl.model.{
ContentTypeRange,
HttpCharsets,
HttpEntity,
MediaType,
RequestEntity,
ResponseEntity
}
import org.apache.pekko.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` }
import org.apache.pekko.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller }
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
import org.apache.pekko.stream.scaladsl.{ Sink, Source }
import org.apache.pekko.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller }
import cats.data.{ NonEmptyList, ValidatedNel }
import io.circe.{ DecodingFailure, Encoder, ParsingFailure, Printer }
import io.circe.CursorOp.DownField
import org.scalatest.{ BeforeAndAfterAll, EitherValues }
import io.circe.{ DecodingFailure, ParsingFailure, Printer }
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
import org.scalatest.{ BeforeAndAfterAll, EitherValues }

import scala.concurrent.Await
import scala.concurrent.duration.DurationInt

Expand Down Expand Up @@ -79,24 +72,6 @@ final class CirceSupportSpec
.map(_ shouldBe foo)
}

"enable streamed marshalling and unmarshalling for json arrays" in {
val foos = (0 to 100).map(i => Foo(s"bar-$i")).toList

// Don't know why, the encoder is not resolving alongside the marshaller
// this only happens if we use the implicits from BaseCirceSupport
// so, tried to create it before and guess what? it worked.
// not sure if this is a bug, but, the error is this:
// diverging implicit expansion for type io.circe.Encoder[A]
// [error] starting with lazy value encodeZoneOffset in object Encoder
implicit val e = implicitly[Encoder[Foo]]

Marshal(Source(foos))
.to[ResponseEntity]
.flatMap(entity => Unmarshal(entity).to[SourceOf[Foo]])
.flatMap(_.runWith(Sink.seq))
.map(_ shouldBe foos)
}

"provide proper error messages for requirement errors" in {
val entity = HttpEntity(`application/json`, """{ "bar": "baz" }""")
Unmarshal(entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object ExampleApp {
private final case class Foo(bar: String)

def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val system: ActorSystem = ActorSystem()

Http().newServerAt("127.0.0.1", 8000).bindFlow(route)

Expand All @@ -54,7 +54,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 @@ -31,7 +31,7 @@ object ExampleApp {
final case class Foo(bar: String)

def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val system: ActorSystem = ActorSystem()

// provide an implicit ObjectMapper if you want serialization/deserialization to use it
// instead of a default ObjectMapper configured only with DefaultScalaModule provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ExampleApp {
private final case class Foo(bar: String)

def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val system: ActorSystem = ActorSystem()

Http().newServerAt("127.0.0.1", 8000).bindFlow(route)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class NinnySupportSpec extends AsyncWordSpec with Matchers with BeforeAndA
import NinnySupportSpec._
import io.github.kag0.ninny.Auto._

private implicit val system = ActorSystem()
private implicit val system: ActorSystem = ActorSystem()

"NinnySupport" should {
"enable marshalling and unmarshalling objects for which `ToJson` and `FromSomeJson` exist" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object ExampleApp {
final case class Foo(bar: String)

def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val system: ActorSystem = ActorSystem()

Http().newServerAt("127.0.0.1", 8000).bindFlow(route)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class PlayJsonSupportSpec extends AsyncWordSpec with Matchers with BeforeA
import PlayJsonSupport._
import PlayJsonSupportSpec._

private implicit val system = ActorSystem()
private implicit val system: ActorSystem = ActorSystem()

"PlayJsonSupport" should {
"enable marshalling and unmarshalling objects for which `Writes` and `Reads` exist" in {
Expand Down
Loading