Skip to content

Instantly share code, notes, and snippets.

@vinh0604
Created February 26, 2016 14:40
Show Gist options
  • Save vinh0604/871273a56b0c10909a40 to your computer and use it in GitHub Desktop.
Save vinh0604/871273a56b0c10909a40 to your computer and use it in GitHub Desktop.
json4s-jackson custom serializer for Joda Money
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