model.CurrencyJSONCodec.kt Maven / Gradle / Ivy
package com.github.fluidsonic.baku
import com.github.fluidsonic.fluid.json.*
import java.util.Currency
internal object CurrencyJSONCodec : AbstractJSONCodec() {
override fun JSONDecoder.decode(valueType: JSONCodingType) =
readString().let { code ->
runCatching { Currency.getInstance(code) }.getOrNull() ?: invalidValueError("'$code' is not a valid ISO 4217 currency code")
}
override fun JSONEncoder.encode(value: Currency) {
writeString(value.currencyCode)
}
}