model.CountryJSONCodec.kt Maven / Gradle / Ivy
package com.github.fluidsonic.baku
import com.github.fluidsonic.fluid.json.*
internal object CountryJSONCodec : AbstractJSONCodec() {
override fun JSONDecoder.decode(valueType: JSONCodingType) =
readString().let { code ->
Country.byCode(code) ?: invalidValueError("'$code' is not a valid IANA country code")
}
override fun JSONEncoder.encode(value: Country) {
writeString(value.code)
}
}