Last active
May 3, 2020 15:26
-
-
Save kenoir/92bf4aa7974b4ffeaa6e957bf4856e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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