case class ServiceID(id: String) extends AnyVal
case class Hostname(name: String) extends AnyVal
case class Service(id: ServiceID, host: Hostname) extends AvroRecord
Generating schema AvroRecord.inferSchema[Service] will look like this:
Serialization/Deserialization of this is not working but it's not difficult to do so, however the question is whether this is the right representation of value classes. It would be nicer to represent this as a primitive whose logicalType is the value class name. This doesn't necessarily port outside java but other languages can simply take the primitive value form. It needs to be tested whether custom/dynamic logical types are actually allowed by the avro specification. If yes we could also port types currently using runtime attribute to represent custom logical types.
The above schema with logialType applied would look like this:
Currently if we have a domain like this:
Generating schema
AvroRecord.inferSchema[Service]
will look like this:Serialization/Deserialization of this is not working but it's not difficult to do so, however the question is whether this is the right representation of value classes. It would be nicer to represent this as a primitive whose logicalType is the value class name. This doesn't necessarily port outside java but other languages can simply take the primitive value form. It needs to be tested whether custom/dynamic logical types are actually allowed by the avro specification. If yes we could also port types currently using
runtime
attribute to represent custom logical types.The above schema with logialType applied would look like this: