Skip to content

Instantly share code, notes, and snippets.

@joost-de-vries
Last active December 31, 2015 06:09
Show Gist options
  • Save joost-de-vries/7946056 to your computer and use it in GitHub Desktop.
Save joost-de-vries/7946056 to your computer and use it in GitHub Desktop.
Workaround om Play json combinators te kunnen gebruiken bij case classes met één veld
import scala.language.higherKinds
import play.api.libs.functional.InvariantFunctor
object JsonCombinatorUtil {
/** workaround voor issue dat json combinators niet kunnen omgaan met case classes met 1 veld
* zie http://stackoverflow.com/questions/15042205/how-to-serialize-deserialize-case-classes-to-from-json-in-play-2-1 */
implicit class FormatBuilder[M[_], A](o: M[A]) {
def build[B](f1: A => B, f2: B => A)(implicit fu: InvariantFunctor[M]) =
fu.inmap[A, B](o, f1, f2)
}
}
import JsonCombinatorUtil._
case class MijnObject(veld:String)
object MijnObject {
implicit val moFormat = ((__ \ "uri").format[String]) build (MijnObject.apply _, unlift(MijnObject.unapply))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment