Created
March 29, 2016 21:20
-
-
Save dabd/432687c972e939bba68002bf9bdbd24a to your computer and use it in GitHub Desktop.
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 play.api.libs.json.{Format, JsResult, JsValue, Json} | |
import shapeless.tag.@@ | |
trait Money | |
case class Amount(price: String @@ Money) | |
private val amountWrites = Json.writes[Amount] | |
private val amountReads = Json.reads[Amount] | |
implicit val format: Format[Amount] = new Format[Amount] { | |
override def writes(amount: Amount): JsValue = Json.toJson(amount)(amountWrites) | |
override def reads(json: JsValue): JsResult[Amount] = Json.fromJson[Amount](json)(amountReads) | |
} | |
implicit val formatMoney: Format[String @@ Money] = new Format[@@[String, Money]] { | |
override def writes(o: @@[String, Money]): JsValue = Json.toJson(o)(Json.writes[String @@ Money]) | |
override def reads(json: JsValue): JsResult[@@[String, Money]] = Json.fromJson[String @@ Money](json)(Json.reads[String @@ Money]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment