This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Add scala 3 support for uPickle, Jackson and Circe #757
Open
DieBauer
wants to merge
3
commits into
hseeberger:master
Choose a base branch
from
DieBauer:scala3-part2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
akka-http-circe/src/test/scala-2/de/heikoseeberger/akkahttpcirce/CirceSupportSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 de.heikoseeberger.akkahttpcirce | ||
|
||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.marshalling.Marshal | ||
import akka.http.scaladsl.model._ | ||
import akka.http.scaladsl.unmarshalling.Unmarshal | ||
import akka.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() | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
akka-http-circe/src/test/scala-3/de/heikoseeberger/akkahttpcirce/CirceSupportSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 de.heikoseeberger.akkahttpcirce | ||
|
||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.marshalling.Marshal | ||
import akka.http.scaladsl.model._ | ||
import akka.http.scaladsl.unmarshalling.Unmarshal | ||
import akka.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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rename the file to CirceSupportSpec2.scala (likewise in scala-2 dir)?