Created
October 20, 2011 04:32
-
-
Save ctcarrier/1300421 to your computer and use it in GitHub Desktop.
Spray lift-json support
This file contains 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
implicit def liftJsonUnmarshaller[A :Manifest] = new UnmarshallerBase[A] { | |
val canUnmarshalFrom = ContentTypeRange(`application/json`) :: Nil | |
def unmarshal(content: HttpContent) = protect { | |
val jsonSource = DefaultUnmarshallers.StringUnmarshaller.unmarshal(content).right.get | |
parse(jsonSource).extract[A] | |
} | |
} | |
implicit def liftJsonMarshaller[A <: AnyRef] = new MarshallerBase[A] { | |
val canMarshalTo = ContentType(`application/json`) :: Nil | |
def marshal(value: A, contentType: ContentType) = { | |
val jsonSource = write(value) | |
DefaultMarshallers.StringMarshaller.marshal(jsonSource, contentType) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment