James Moore
James Moore

Reputation: 9026

What's the best way to serialize a scala case class that has elements that aren't serializable?

If you have a Scala case class that looks like:

case class Fnord(x: Parcelable, y: Parcelable)

Where Parcelable doesn't extend Serializable, but does have a way to return a ByteArray of itself (something that does implement Serializable).

How to do you make the case class Serializable? Is there a way to do custom (de)serialization on particular fields?

(I'm solving it right now by creating a simple wrapper class that is serializable and using that in the case classes, but it'd be nice to skip that step.)

Upvotes: 3

Views: 736

Answers (1)

Dave Whittaker
Dave Whittaker

Reputation: 3102

Take a look at java.io.Externalizable. It allows a class to manually serialize and restore its fields.

Upvotes: 1

Related Questions