Skip to content

Instantly share code, notes, and snippets.

@kenoir
Last active May 3, 2020 15:26
Show Gist options
  • Save kenoir/92bf4aa7974b4ffeaa6e957bf4856e25 to your computer and use it in GitHub Desktop.
Save kenoir/92bf4aa7974b4ffeaa6e957bf4856e25 to your computer and use it in GitHub Desktop.
package things
import java.time.Instant
import com.sksamuel.avro4s.AvroSchema
import org.apache.avro.Schema
object World extends App {
sealed trait User {
val name: String
}
case class SpecialUser(name: String, age: Int, birthday: Instant) extends User
case class PlainUser(name: String) extends User
case class BetterButNotAsGoodAsSpecial(name: String, age: Int) extends User
val schema: Schema = AvroSchema[User]
val output: String = schema.toString
println(output)
}
[
{
"type": "record",
"name": "BetterButNotAsGoodAsSpecial",
"namespace": "things.World",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "age",
"type": "int"
}
]
},
{
"type": "record",
"name": "PlainUser",
"namespace": "things.World",
"fields": [
{
"name": "name",
"type": "string"
}
]
},
{
"type": "record",
"name": "SpecialUser",
"namespace": "things.World",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "age",
"type": "int"
},
{
"name": "birthday",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment