From f560a8f56731ce55644333ff35c6d9e733726abc Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Wed, 11 Apr 2018 23:30:05 -0500 Subject: [PATCH] server: Add serializer for the Balance model --- server/app/com/xsn/explorer/models/Balance.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/app/com/xsn/explorer/models/Balance.scala b/server/app/com/xsn/explorer/models/Balance.scala index 6281526..01527cc 100644 --- a/server/app/com/xsn/explorer/models/Balance.scala +++ b/server/app/com/xsn/explorer/models/Balance.scala @@ -1,5 +1,7 @@ package com.xsn.explorer.models +import play.api.libs.json._ + case class Balance( address: Address, received: BigDecimal = BigDecimal(0), @@ -7,3 +9,15 @@ case class Balance( def available: BigDecimal = received - spent } + +object Balance { + implicit val writes: Writes[Balance] = Writes { obj => + val values = Map( + "address" -> JsString(obj.address.string), + "received" -> JsNumber(obj.received), + "spent" -> JsNumber(obj.spent), + "available" -> JsNumber(obj.available)) + + JsObject.apply(values) + } +}