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

model.CurrencyBSONCodec.kt Maven / Gradle / Ivy

There is a newer version: 0.9.27
Show newest version
package com.github.fluidsonic.baku

import org.bson.BsonReader
import org.bson.BsonWriter
import java.util.Currency


internal object CurrencyBSONCodec : AbstractBSONCodec() {

	override fun BsonReader.decode(context: BSONCodingContext) =
		readString().let { code ->
			runCatching { Currency.getInstance(code) }.getOrNull() ?: throw BSONException("Invalid currency code '$code'")
		}


	override fun BsonWriter.encode(value: Currency, context: BSONCodingContext) {
		writeString(value.currencyCode)
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy