Last active
December 31, 2015 06:09
-
-
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
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
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