All Downloads are FREE. Search and download functionalities are using the official Maven repository.

model.CurrencyJSONCodec.kt Maven / Gradle / Ivy

There is a newer version: 0.9.27
Show newest version
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)
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy