model.CurrencyJSONCodec.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of baku Show documentation
Show all versions of baku Show documentation
helps you focus your REST API back-end on the business logic
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)
}
}