Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement interface Serializable in scala?

Tags:

scala

I have scala class like:

@Entity("users")
class User(@Required val cid: String, val isAdmin: Boolean = false, @Required val dateJoined: Date = new Date() ) {
  @Id var id: ObjectId = _



    @Reference
  val foos = new ArrayList[Foo]

    }

If it was a Java class I would simply put implements java.io.Serializable but this does not work in scala. Also is foos as declared above is private or public?

like image 393
rjc Avatar asked Jul 01 '11 18:07

rjc


2 Answers

How do I use a @serializable scala object?

foos is public unless marked otherwise

like image 174
James Iry Avatar answered Sep 22 '22 13:09

James Iry


scala 2.9.x also have an interface named Serializable, you may extends or mixin this. before 2.9.x the @serializable is the only choice.

like image 34
jilen Avatar answered Sep 22 '22 13:09

jilen