Skip to content

Commit

Permalink
Support for Play 3
Browse files Browse the repository at this point in the history
  • Loading branch information
gmethvin committed May 9, 2024
1 parent c27ef14 commit 17e9b47
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ developers := List(
Developer(id = "Iterable", name = "Iterable", email = "[email protected]", url = url("https://iterable.com"))
)

scalaVersion := "2.13.5"
crossScalaVersions := Seq(scalaVersion.value, "2.12.13")
scalaVersion := "2.13.14"

val PlayVersion = "2.8.6"
val PlayVersion = "3.0.1"

libraryDependencies ++= Seq(
// Play! framework
"com.typesafe.play" %% "play" % PlayVersion,
"com.typesafe.play" %% "play-joda-forms" % PlayVersion,
"org.playframework" %% "play" % PlayVersion,
"org.playframework" %% "play-joda-forms" % PlayVersion,
// dependencies for tests
"org.scalatest" %% "scalatest" % "3.2.5" % Test
"org.scalatest" %% "scalatest" % "3.2.18" % Test
)

parallelExecution in Test := false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object CaseClassMapping extends Logging {
}

private def generateWrappedMappingForFormatter(fieldName: String, tpe: Type, formatter: Formatter[_]): Mapping[_] = {
val mapping = FieldMapping("")(formatter.asInstanceOf[Formatter[Any]])
@annotation.nowarn val mapping = FieldMapping("")(formatter.asInstanceOf[Formatter[Any]])
generateWrappedMappingForMapping(fieldName, tpe, mapping)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import play.api.data.{Form, FormError, Mapping}

case class Baz(pls: String, work: Option[Long])
object Baz {
implicit val mapping = CaseClassMapping.mapping[Baz]
implicit val mapping: CaseClassMapping[Baz] = CaseClassMapping.mapping
}

case class Foo(a: String, omg: Option[Seq[Baz]])
object Foo {
implicit def mapping = CaseClassMapping.mapping[Foo]
implicit def mapping: CaseClassMapping[Foo] = CaseClassMapping.mapping
}

case class Bar(firstOne: Option[List[Long]], secondOne: String, third: Option[Foo], fourth: Option[Int]) extends UnbindableToWsRequest[Bar]
object Bar {
implicit val mapping = CaseClassMapping.mapping[Bar]
implicit val mapping: CaseClassMapping[Bar] = CaseClassMapping.mapping
}

class CaseClassMappingSpec extends AnyWordSpec with Matchers {
// TODO - it breaks on this, because
// scala.ScalaReflectionException: class Bar2 is an inner class, use reflectClass on an InstanceMirror to obtain its ClassMirror
case class Bar2(firstOne: Int)
object Bar2 {
implicit lazy val mapping = CaseClassMapping.mapping[Bar2]
implicit lazy val mapping: CaseClassMapping[Bar2] = CaseClassMapping.mapping
}

"CaseClassMapping" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.scalatest.wordspec.AnyWordSpec

case class User(name: String, age: Int, email: String, favoriteBands: Seq[String]) extends UnbindableToWsRequest[User]
object User {
implicit val mapping = CaseClassMapping.mapping[User]
implicit val mapping: CaseClassMapping[User] = CaseClassMapping.mapping
}

class UnbindableToWsRequestSpec extends AnyWordSpec with Matchers {
Expand Down

0 comments on commit 17e9b47

Please sign in to comment.