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

model.EntityIdJSONCodec.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.*


internal class EntityIdJSONCodec(
	private val factory: EntityId.Factory
) : JSONCodec {

	override val decodableType = jsonCodingType(factory.idClass)


	override fun JSONDecoder.decode(valueType: JSONCodingType) =
		readString().let { string ->
			factory.parse(string) ?: invalidValueError("'$string' is not a valid '${factory.type}' ID")
		}


	override fun JSONEncoder.encode(value: Id) {
		writeString(factory.serialize(value))
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy