Created
February 26, 2016 14:40
-
-
Save vinh0604/871273a56b0c10909a40 to your computer and use it in GitHub Desktop.
json4s-jackson custom serializer for Joda Money
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
class JodaMoneySerializer extends CustomSerializer[Money](format => ( | |
{ | |
case JObject(JField("value", JDecimal(value)) :: JField("currency", JString(currency)) :: Nil) => | |
Money.of(CurrencyUnit.getInstance(currency), value.bigDecimal) | |
}, | |
{ | |
case money: Money => | |
JObject( | |
JField("value", JDecimal(BigDecimal(money.getAmount))) :: | |
JField("currency", JString(money.getCurrencyUnit.getCurrencyCode)) :: | |
JField("symbol", JString(CurrencySymbol.symbol(money.getCurrencyUnit.getCurrencyCode))) :: Nil) | |
} | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment