Skip to content

Fix upickle problem #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ libraryDependencies ++= Seq(
"commons-io" % "commons-io" % "2.11.0",
"com.typesafe.akka" %% "akka-actor" % "2.6.20",
"com.typesafe.akka" %% "akka-testkit" % "2.6.20" % "test",
"org.scalatest" %% "scalatest" % "3.2.14" % "test"
"org.scalatest" %% "scalatest" % "3.2.14" % "test",
"com.lihaoyi" %% "upickle" % "2.0.0"
)

import org.scoverage.coveralls.Imports.CoverallsKeys._
Expand Down
25 changes: 25 additions & 0 deletions src/main/scala/org/scoverage/samples/CustomPicklers.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.scoverage.samples

import upickle._

/**
* Json boilerplate.
* - Parse null and missing objects into scala Options
*/
object CustomPicklers {

object OptionPickler extends upickle.AttributeTagged {
override implicit def OptionWriter[T: Writer]: Writer[Option[T]] =
implicitly[Writer[T]].comap[Option[T]] {
case None => null.asInstanceOf[T]
case Some(x) => x
}

override implicit def OptionReader[T: Reader]: Reader[Option[T]] = {
new Reader.Delegate[Any, Option[T]](implicitly[Reader[T]].map(Some(_))) {
override def visitNull(index: Int) = None
}
}
}

}
16 changes: 16 additions & 0 deletions src/main/scala/org/scoverage/samples/UpickleStuff.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.scoverage.samples

import org.scoverage.samples.CustomPicklers.OptionPickler.{
ReadWriter => RW,
macroRW
}

object UpickleStuff {
case class Person(
name: String
)

object Person {
implicit val rw: RW[Person] = macroRW
}
}