Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Update ninny package names and add Scala 3 (#836)
Browse files Browse the repository at this point in the history
* Update ninny package names and add scala 3

* compile for scala 3
  • Loading branch information
nrktkt authored Nov 16, 2023
1 parent 291e97d commit f5099a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import akka.http.scaladsl.unmarshalling.{ FromEntityUnmarshaller, Unmarshal, Unm
import akka.http.scaladsl.util.FastFuture
import akka.stream.scaladsl.{ Flow, Source }
import akka.util.ByteString
import io.github.kag0.ninny._
import nrktkt.ninny._
import java.nio.charset.StandardCharsets
import scala.collection.immutable.Seq
import scala.concurrent.Future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ import akka.stream.scaladsl.Source

import scala.concurrent.duration._
import scala.io.StdIn
import nrktkt.ninny._

object ExampleApp {

private final case class Foo(bar: String)
private object Foo {
implicit val toJson: ToSomeJson[Foo] = foo => obj("bar" --> foo.bar)
implicit val fromJson: FromJson[Foo] = FromJson.fromSome(_.bar.to[String].map(Foo(_)))
}

def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
Expand All @@ -43,7 +48,6 @@ object ExampleApp {
private def route(implicit sys: ActorSystem) = {
import Directives._
import NinnySupport._
import io.github.kag0.ninny.Auto._

pathSingleSlash {
post {
Expand All @@ -55,7 +59,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 @@ -23,7 +23,7 @@ import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(U
import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller }
import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
import akka.stream.scaladsl.{ Sink, Source }
import io.github.kag0.ninny.JsonException
import nrktkt.ninny._
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
Expand All @@ -35,14 +35,17 @@ object NinnySupportSpec {
final case class Foo(bar: String) {
require(bar startsWith "bar", "bar must start with 'bar'!")
}
private object Foo {
implicit val toJson: ToSomeJson[Foo] = foo => obj("bar" --> foo.bar)
implicit val fromJson: FromJson[Foo] = FromJson.fromSome(_.bar.to[String].map(Foo(_)))
}
}

final class NinnySupportSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
import NinnySupport._
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 Expand Up @@ -78,7 +81,7 @@ final class NinnySupportSpec extends AsyncWordSpec with Matchers with BeforeAndA
.failed
.map { err =>
err shouldBe a[JsonException]
err should have message "Error converting bar from JSON: Expected string, got 5"
err should have message "Expected string, got 5"
}
}

Expand All @@ -105,7 +108,7 @@ final class NinnySupportSpec extends AsyncWordSpec with Matchers with BeforeAndA
val `application/json-home` =
MediaType.applicationWithFixedCharset("json-home", HttpCharsets.`UTF-8`, "json-home")

final object CustomNinnySupport extends NinnySupport {
object CustomNinnySupport extends NinnySupport {
override def unmarshallerContentTypes = List(`application/json`, `application/json-home`)
}
import CustomNinnySupport._
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ lazy val `akka-http-jsoniter-scala` =
lazy val `akka-http-ninny` =
project
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(commonSettings, withScala3)
.settings(
libraryDependencies ++= Seq(
library.akkaHttp,
Expand Down

0 comments on commit f5099a1

Please sign in to comment.