Skip to content

Instantly share code, notes, and snippets.

@sam
Created March 18, 2013 15:43
Show Gist options
  • Save sam/5188102 to your computer and use it in GitHub Desktop.
Save sam/5188102 to your computer and use it in GitHub Desktop.
Definining a Generic JsonFormat. If SequentialId weren't a Generic, this would be easy. Since it is, and I want to serialize it directly to a String (not as a case-class containing an "id" field), I'm having trouble...
import spray.json._
class Model {
implicit object SequentialIdJsonFormat extends JsonFormat[SequentialId] {
def write(x: SequentialId) = JsString(x.id)
def read[T](value:JsValue):SequentialId = value match {
case JsString(x) => SequentialId[T](x)
case x => deserializationError("Expected SequentialId as JsString, but got " + x)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment