Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

mirkonasato/seriala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Seriala

A serialization library for Scala.

This is in experimental stage, started as a way to try out the then new Scala 2.10 reflection API, and now updated for Scala 2.11.

Design Goals

  • Serializable objects should be regular Scala classes (no annotations, no base trait)
  • Support multiple formats; currently JSON (using Jackson) and Avro
  • For schema-based formats, support generating the schema from Scala classes, or vice-versa

JSON Example

scala> case class User(id: Int, name: String, groups: List[String])
defined class User

scala> val joe = User(1000, "joe", List("admin", "staff"))
joe: User = User(1000,joe,List(admin, staff))

scala> val json = JsonFactory.toString(joe)
json: String = {"id":1000,"name":"joe","groups":["admin","staff"]}

scala> val joe2 = JsonFactory.fromString[User](json)
joe2: User = User(1000,joe,List(admin, staff))

Avro Example

DatumWriter and DatumReader implementations are provided for dealing with Avro files:

val avroSchema = SchemaConversions.toAvroSchema(Schema.schemaOf[User])

val datumWriter = new ScalaDatumWriter[User]
val fileWriter = new DataFileWriter(datumWriter)
fileWriter.create(avroSchema, file)
fileWriter.append(user)
// ...
fileWriter.close()

val datumReader = new ScalaDatumReader[User]
val fileReader = new DataFileReader(file, datumReader)
while (fileReader.hasNext()) {
  val user = fileReader.next()
}

About

Serialization for Scala.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages