Created
March 18, 2013 15:43
-
-
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...
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
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