Last active
August 29, 2015 14:27
-
-
Save nelanka/241e77153edcc27b5a06 to your computer and use it in GitHub Desktop.
Serialize and deserialize case classes with helper object
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
case class IdentifierKey(idType: String, id: String) { | |
override def toString: String = SerializedIdentifierKey(this) | |
} | |
object SerializedIdentifierKey extends (IdentifierKey => String) { | |
val delimiter = ':' | |
def apply(i: IdentifierKey): String = i.idType + SerializedIdentifierKey.delimiter + i.id | |
def unapply(s: String): Option[IdentifierKey] = { | |
val Array(idType, id) = s.split(SerializedIdentifierKey.delimiter) | |
Some(IdentifierKey(idType, id)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment